4
4
5
5
use Exception ;
6
6
use PHPModelGenerator \Exception \ErrorRegistryException ;
7
+ use PHPModelGenerator \Exception \Generic \InvalidTypeException ;
7
8
use PHPModelGenerator \Exception \Object \InvalidAdditionalPropertiesException ;
8
9
use PHPModelGenerator \Exception \Object \InvalidPropertyNamesException ;
9
10
use PHPModelGenerator \Exception \Object \MaxPropertiesException ;
@@ -75,7 +76,7 @@ public function testInvalidPopulateThrowsAnException(
75
76
76
77
$ className = $ this ->generateClassFromFile (
77
78
'BasicSchema.json ' ,
78
- (new GeneratorConfiguration ())->setCollectErrors ($ collectErrors )
79
+ (new GeneratorConfiguration ())->setCollectErrors ($ collectErrors )-> setSerialization ( true )
79
80
);
80
81
$ object = new $ className (['name ' => 'Albert ' , 'age ' => 30 ]);
81
82
@@ -85,6 +86,7 @@ public function testInvalidPopulateThrowsAnException(
85
86
} catch (Exception $ exception ) {
86
87
// test if the internal state hasn't been changed
87
88
$ this ->assertSame (['name ' => 'Albert ' , 'age ' => 30 ], $ object ->getRawModelDataInput ());
89
+ $ this ->assertSame (['name ' => 'Albert ' , 'age ' => 30 ], $ object ->toArray ());
88
90
89
91
throw $ exception ;
90
92
}
@@ -99,6 +101,18 @@ public function invalidPopulateDataProvider(): array
99
101
PatternException::class,
100
102
"Value for name doesn't match pattern ^[a-zA-Z]*$ "
101
103
],
104
+ 'No error collection - first value ok second invalid ' => [
105
+ ['name ' => 'Hannes ' , 'age ' => false ],
106
+ false ,
107
+ InvalidTypeException::class,
108
+ "Invalid type for age. Requires int, got boolean "
109
+ ],
110
+ 'Error collection - first value ok second invalid ' => [
111
+ ['name ' => 'Hannes ' , 'age ' => false ],
112
+ true ,
113
+ ErrorRegistryException::class,
114
+ "Invalid type for age. Requires int, got boolean "
115
+ ],
102
116
'Error collection - multiple violations ' => [
103
117
['name ' => 'Anne-Marie ' , 'age ' => false ],
104
118
true ,
0 commit comments