@@ -29,20 +29,42 @@ public function testApplyMethodAppliesSchemaObjectToPost()
2929 $ schemaObject = Schema::thing ()->name ('Foo ' );
3030 $ schemaObjectFromPost = $ this ->getSchemaObjectFromPostInstance ();
3131 $ schemaObjectFromPost ->method ('create ' )->willReturn ($ schemaObject );
32+ $ innerPostObject = $ this ->getPostObject ();
33+ $ innerPostObject ->method ('getId ' )->willReturn (123 );
3234
33- $ postObject = new PostObjectWithSchemaObject ($ this -> getPostObject () , $ schemaObjectFromPost );
35+ $ postObject = new PostObjectWithSchemaObject ($ innerPostObject , $ schemaObjectFromPost );
3436
3537 $ this ->assertSame ('Thing ' , $ postObject ->getSchemaProperty ('@type ' ));
3638 $ this ->assertSame ('Foo ' , $ postObject ->getSchemaProperty ('name ' ));
3739 }
3840
41+ /**
42+ * @testdox caches schema object per post ID
43+ */
44+ public function testCachesSchemaObjectPerPostId ()
45+ {
46+ // Arrange
47+ $ schemaObject = Schema::thing ()->name ('Foo ' );
48+ $ schemaObjectFromPost = $ this ->getSchemaObjectFromPostInstance ();
49+ $ innerPostObject = $ this ->getPostObject ();
50+ $ innerPostObject ->method ('getId ' )->willReturn (321 );
51+ $ postObject = new PostObjectWithSchemaObject ($ this ->getPostObject (), $ schemaObjectFromPost );
52+
53+ // Assert
54+ $ schemaObjectFromPost ->expects ($ this ->once ())->method ('create ' )->willReturn ($ schemaObject );
55+
56+ // Act
57+ $ postObject ->getSchemaProperty ('@type ' );
58+ $ postObject ->getSchemaProperty ('name ' );
59+ }
60+
3961 private function getSchemaObjectFromPostInstance (): SchemaObjectFromPostInterface |MockObject
4062 {
4163 return $ this ->createMock (SchemaObjectFromPostInterface::class);
4264 }
4365
44- private function getPostObject (): PostObjectInterface
66+ private function getPostObject (): PostObjectInterface | MockObject
4567 {
46- return new PostObject ( 1 , new FakeWpService () );
68+ return $ this -> createMock (PostObjectInterface::class );
4769 }
4870}
0 commit comments