@@ -57,6 +57,16 @@ public function testInheritance(): void
5757 $ this ->assertNotSame ($ subclassB11 ,$ subclassC11 );
5858 }
5959
60+ public function testInheritanceWithoutParentConstructor (): void
61+ {
62+ try {
63+ SubclassWithConstructorType::fromFoo ('1 ' );
64+ $ this ->expectNotToPerformAssertions ();
65+ } catch (\Throwable $ e ) {
66+ $ this ->fail (sprintf ('Unable to instantiate value object subclass without parent constructor: %s ' , $ e ));
67+ }
68+ }
69+
6070 public function testNoMutation (): void
6171 {
6272 $ testObject = FromValuesType::fromFooAndBar ('foo ' , 1 );
@@ -136,8 +146,8 @@ public function getCasesForValueTypes(): array
136146 $ stdClassB = new \stdClass ();
137147 $ stdClassB ->foo = 'bar ' ;
138148
139- $ objectA = new Object ();
140- $ objectB = new Object ();
149+ $ objectA = new ObjectClass ();
150+ $ objectB = new ObjectClass ();
141151
142152 $ resourceA = fopen (__DIR__ . '/test_resource ' , 'r ' );
143153 $ resourceB = fopen (__DIR__ . '/test_resource ' , 'r ' );
@@ -227,7 +237,7 @@ public function getValue()
227237 }
228238}
229239
230- class Object {}
240+ class ObjectClass {}
231241
232242class FromValuesType
233243{
@@ -363,3 +373,31 @@ public function getBarC(): int
363373 return $ this ->barC ;
364374 }
365375}
376+
377+
378+
379+ abstract class SuperclassWithoutConstructorType
380+ {
381+ use ValueObjectTrait;
382+ }
383+
384+ class SubclassWithConstructorType extends SuperclassWithoutConstructorType
385+ {
386+ /** @var string */
387+ private $ foo ;
388+
389+ protected function __construct (string $ foo )
390+ {
391+ $ this ->foo = $ foo ;
392+ }
393+
394+ public static function fromFoo (string $ foo ): self
395+ {
396+ return self ::getInstance ($ foo );
397+ }
398+
399+ public function getFoo (): string
400+ {
401+ return $ this ->foo ;
402+ }
403+ }
0 commit comments