@@ -15,6 +15,7 @@ final class ArrayMatcher extends Matcher
1515{
1616 const PATTERN = 'array ' ;
1717 const UNBOUNDED_PATTERN = '@...@ ' ;
18+ const UNIVERSAL_KEY = '@*@ ' ;
1819
1920 private $ propertyMatcher ;
2021
@@ -70,18 +71,20 @@ private function iterateMatch(array $values, array $patterns, string $parentPath
7071 foreach ($ values as $ key => $ value ) {
7172 $ path = $ this ->formatAccessPath ($ key );
7273
73- if ($ this ->shouldSkippValueMatchingFor ($ pattern )) {
74+ if ($ this ->shouldSkipValueMatchingFor ($ pattern )) {
7475 continue ;
7576 }
7677
7778 if ($ this ->valueExist ($ path , $ patterns )) {
7879 $ pattern = $ this ->getValueByPath ($ patterns , $ path );
80+ } elseif (isset ($ patterns [self ::UNIVERSAL_KEY ])) {
81+ $ pattern = $ patterns [self ::UNIVERSAL_KEY ];
7982 } else {
8083 $ this ->setMissingElementInError ('pattern ' , $ this ->formatFullPath ($ parentPath , $ path ));
8184 return false ;
8285 }
8386
84- if ($ this ->shouldSkippValueMatchingFor ($ pattern )) {
87+ if ($ this ->shouldSkipValueMatchingFor ($ pattern )) {
8588 continue ;
8689 }
8790
@@ -138,9 +141,13 @@ function ($item) use ($skipPattern) {
138141 return true ;
139142 }
140143
141- private function findNotExistingKeys (array $ pattern , array $ values ) : array
144+ private function findNotExistingKeys (array $ patterns , array $ values ) : array
142145 {
143- $ notExistingKeys = \array_diff_key ($ pattern , $ values );
146+ if (isset ($ patterns [self ::UNIVERSAL_KEY ])) {
147+ return [];
148+ }
149+
150+ $ notExistingKeys = \array_diff_key ($ patterns , $ values );
144151
145152 return \array_filter ($ notExistingKeys , function ($ pattern ) use ($ values ) {
146153 if (\is_array ($ pattern )) {
@@ -230,7 +237,7 @@ private function formatFullPath(string $parentPath, string $path) : string
230237 return \sprintf ('%s%s ' , $ parentPath , $ path );
231238 }
232239
233- private function shouldSkippValueMatchingFor ($ lastPattern ) : bool
240+ private function shouldSkipValueMatchingFor ($ lastPattern ) : bool
234241 {
235242 return $ lastPattern === self ::UNBOUNDED_PATTERN ;
236243 }
0 commit comments