1
1
<?php
2
2
3
- namespace PHPModelGenerator \Tests \Basic ;
3
+ namespace PHPModelGenerator \Tests \Objects ;
4
4
5
+ use PHPModelGenerator \Exception \ErrorRegistryException ;
5
6
use PHPModelGenerator \Exception \FileSystemException ;
6
7
use PHPModelGenerator \Exception \ValidationException ;
7
8
use PHPModelGenerator \Exception \RenderException ;
@@ -41,6 +42,7 @@ public function requiredDefinitionsDataProvider(): array
41
42
[
42
43
'Defined property ' => ['RequiredStringProperty.json ' ],
43
44
'Undefined property ' => ['RequiredUndefinedProperty.json ' ],
45
+ 'Reference in composition ' => ['RequiredReferencePropertyInComposition.json ' ],
44
46
]
45
47
);
46
48
}
@@ -67,12 +69,12 @@ public function validStringPropertyValueProvider(): array
67
69
*/
68
70
public function testNotProvidedRequiredPropertyThrowsAnException (bool $ implicitNull , string $ file ): void
69
71
{
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/ " );
72
74
73
75
$ className = $ this ->generateClassFromFile (
74
76
$ file ,
75
- (new GeneratorConfiguration ())->setCollectErrors (false ),
77
+ (new GeneratorConfiguration ())->setCollectErrors (true ),
76
78
false ,
77
79
$ implicitNull
78
80
);
@@ -81,14 +83,14 @@ public function testNotProvidedRequiredPropertyThrowsAnException(bool $implicitN
81
83
}
82
84
83
85
/**
84
- * @dataProvider implicitNullDataProvider
86
+ * @dataProvider requiredStringPropertyDataProvider
85
87
*
86
88
* @param bool $implicitNull
87
89
*/
88
- public function testRequiredPropertyType (bool $ implicitNull ): void
90
+ public function testRequiredPropertyType (bool $ implicitNull, string $ schemaFile ): void
89
91
{
90
92
$ className = $ this ->generateClassFromFile (
91
- ' RequiredStringProperty.json ' ,
93
+ $ schemaFile ,
92
94
(new GeneratorConfiguration ())->setImmutable (false ),
93
95
false ,
94
96
$ implicitNull
@@ -125,26 +127,37 @@ public function testUndefinedRequiredPropertyType(bool $implicitNull): void
125
127
}
126
128
127
129
/**
128
- * @dataProvider implicitNullDataProvider
130
+ * @dataProvider requiredStringPropertyDataProvider
129
131
*
130
132
* @param bool $implicitNull
131
133
*
132
134
* @throws FileSystemException
133
135
* @throws RenderException
134
136
* @throws SchemaException
135
137
*/
136
- public function testNullProvidedForRequiredPropertyThrowsAnException (bool $ implicitNull ): void
138
+ public function testNullProvidedForRequiredPropertyThrowsAnException (bool $ implicitNull, string $ schemaFile ): void
137
139
{
138
- $ this ->expectException (ValidationException ::class);
139
- $ this ->expectExceptionMessage ( " Invalid type for property " );
140
+ $ this ->expectException (ErrorRegistryException ::class);
141
+ $ this ->expectExceptionMessageMatches ( " / Invalid type for property/ " );
140
142
141
143
$ className = $ this ->generateClassFromFile (
142
- ' RequiredStringProperty.json ' ,
143
- (new GeneratorConfiguration ())->setCollectErrors (false ),
144
+ $ schemaFile ,
145
+ (new GeneratorConfiguration ())->setCollectErrors (true ),
144
146
false ,
145
147
$ implicitNull
146
148
);
147
149
148
150
new $ className (['property ' => null ]);
149
151
}
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
+ }
150
163
}
0 commit comments