11<?php
22
3- namespace PHPModelGenerator \Tests \Basic ;
3+ namespace PHPModelGenerator \Tests \Objects ;
44
5+ use PHPModelGenerator \Exception \ErrorRegistryException ;
56use PHPModelGenerator \Exception \FileSystemException ;
67use PHPModelGenerator \Exception \ValidationException ;
78use PHPModelGenerator \Exception \RenderException ;
@@ -41,6 +42,7 @@ public function requiredDefinitionsDataProvider(): array
4142 [
4243 'Defined property ' => ['RequiredStringProperty.json ' ],
4344 'Undefined property ' => ['RequiredUndefinedProperty.json ' ],
45+ 'Reference in composition ' => ['RequiredReferencePropertyInComposition.json ' ],
4446 ]
4547 );
4648 }
@@ -67,12 +69,12 @@ public function validStringPropertyValueProvider(): array
6769 */
6870 public function testNotProvidedRequiredPropertyThrowsAnException (bool $ implicitNull , string $ file ): void
6971 {
70- $ this ->expectException (ValidationException ::class);
71- $ this ->expectExceptionMessage ( " Missing required value for property " );
72+ $ this ->expectException (ErrorRegistryException ::class);
73+ $ this ->expectExceptionMessageMatches ( " / Missing required value for property/ " );
7274
7375 $ className = $ this ->generateClassFromFile (
7476 $ file ,
75- (new GeneratorConfiguration ())->setCollectErrors (false ),
77+ (new GeneratorConfiguration ())->setCollectErrors (true ),
7678 false ,
7779 $ implicitNull
7880 );
@@ -81,14 +83,14 @@ public function testNotProvidedRequiredPropertyThrowsAnException(bool $implicitN
8183 }
8284
8385 /**
84- * @dataProvider implicitNullDataProvider
86+ * @dataProvider requiredStringPropertyDataProvider
8587 *
8688 * @param bool $implicitNull
8789 */
88- public function testRequiredPropertyType (bool $ implicitNull ): void
90+ public function testRequiredPropertyType (bool $ implicitNull, string $ schemaFile ): void
8991 {
9092 $ className = $ this ->generateClassFromFile (
91- ' RequiredStringProperty.json ' ,
93+ $ schemaFile ,
9294 (new GeneratorConfiguration ())->setImmutable (false ),
9395 false ,
9496 $ implicitNull
@@ -125,26 +127,37 @@ public function testUndefinedRequiredPropertyType(bool $implicitNull): void
125127 }
126128
127129 /**
128- * @dataProvider implicitNullDataProvider
130+ * @dataProvider requiredStringPropertyDataProvider
129131 *
130132 * @param bool $implicitNull
131133 *
132134 * @throws FileSystemException
133135 * @throws RenderException
134136 * @throws SchemaException
135137 */
136- public function testNullProvidedForRequiredPropertyThrowsAnException (bool $ implicitNull ): void
138+ public function testNullProvidedForRequiredPropertyThrowsAnException (bool $ implicitNull, string $ schemaFile ): void
137139 {
138- $ this ->expectException (ValidationException ::class);
139- $ this ->expectExceptionMessage ( " Invalid type for property " );
140+ $ this ->expectException (ErrorRegistryException ::class);
141+ $ this ->expectExceptionMessageMatches ( " / Invalid type for property/ " );
140142
141143 $ className = $ this ->generateClassFromFile (
142- ' RequiredStringProperty.json ' ,
143- (new GeneratorConfiguration ())->setCollectErrors (false ),
144+ $ schemaFile ,
145+ (new GeneratorConfiguration ())->setCollectErrors (true ),
144146 false ,
145147 $ implicitNull
146148 );
147149
148150 new $ className (['property ' => null ]);
149151 }
152+
153+ public function requiredStringPropertyDataProvider (): array
154+ {
155+ return $ this ->combineDataProvider (
156+ $ this ->implicitNullDataProvider (),
157+ [
158+ 'RequiredStringProperty ' => ['RequiredStringProperty.json ' ],
159+ 'RequiredReferencePropertyInComposition ' => ['RequiredReferencePropertyInComposition.json ' ],
160+ ]
161+ );
162+ }
150163}
0 commit comments