File tree Expand file tree Collapse file tree 2 files changed +33
-9
lines changed
Expand file tree Collapse file tree 2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,16 @@ class Resolver
3131 */
3232 private $ descriptions = [];
3333
34+ /**
35+ * @var bool
36+ */
37+ private $ ignoreErrors ;
38+
39+ public function __construct (bool $ ignoreErrors = false )
40+ {
41+ $ this ->ignoreErrors = $ ignoreErrors ;
42+ }
43+
3444 public function setCallback (string $ field , Closure $ callable ): void
3545 {
3646 $ this ->callbacks [$ field ] = $ callable ;
@@ -171,6 +181,15 @@ public function merge(Resolver $schema): Resolver
171181 return $ this ;
172182 }
173183
184+ /**
185+ * @return array<string>
186+ */
187+ private function resolveAllowedKeys (): array
188+ {
189+ $ allowedKeys = array_merge (array_keys ($ this ->defaults ), $ this ->required );
190+ return $ allowedKeys ;
191+ }
192+
174193 public function definitions (): Definitions
175194 {
176195 $ definitions = [];
@@ -187,13 +206,4 @@ public function definitions(): Definitions
187206
188207 return new Definitions ($ definitions );
189208 }
190-
191- /**
192- * @return array<string>
193- */
194- private function resolveAllowedKeys (): array
195- {
196- $ allowedKeys = array_merge (array_keys ($ this ->defaults ), $ this ->required );
197- return $ allowedKeys ;
198- }
199209}
Original file line number Diff line number Diff line change @@ -33,6 +33,20 @@ public function testThrowsExceptionOnUnknownKey(): void
3333 $ resolver ->resolve (['three ' => 3 ]);
3434 }
3535
36+ public function testIgnoresUnknownKey (): void
37+ {
38+ $ resolver = new Resolver (true );
39+ $ resolver ->setDefaults ([
40+ 'one ' => 1 ,
41+ 'two ' => 2 ,
42+ ]);
43+ $ result = $ resolver ->resolve (['three ' => 3 ]);
44+ self ::assertEquals ([
45+ 'one ' => 1 ,
46+ 'two ' => 2
47+ ]);
48+ }
49+
3650 public function testMergesDefaults (): void
3751 {
3852 $ resolver = new Resolver ();
You can’t perform that action at this time.
0 commit comments