1212use Iterator ;
1313use loophp \iterators \IterableIteratorAggregate ;
1414use loophp \iterators \MultipleIterableAggregate ;
15+ use loophp \iterators \PackIterableAggregate ;
1516use MultipleIterator ;
1617use PHPUnit \Framework \Constraint \Constraint ;
1718
@@ -42,6 +43,45 @@ public function toString(): string
4243 return 'has exactly the same keys and values ' ;
4344 }
4445
46+ protected function additionalFailureDescription ($ other ): string
47+ {
48+ [$ subject , $ other ] = array_map (
49+ static fn (iterable $ iterable ): Iterator => (new IterableIteratorAggregate ($ iterable ))->getIterator (),
50+ [$ this ->subject , $ other ]
51+ );
52+
53+ $ mi = new PackIterableAggregate (
54+ new MultipleIterableAggregate ([$ subject , $ other ], MultipleIterator::MIT_NEED_ALL )
55+ );
56+
57+ foreach ($ mi as $ index => [$ key , $ value ]) {
58+ if (0 !== $ this ->limit && $ index >= $ this ->limit ) {
59+ break ;
60+ }
61+
62+ if ($ key [0 ] !== $ key [1 ]) {
63+ return sprintf ('Expected iterable key is different from subject key at index %s ' , $ index );
64+ }
65+
66+ if ($ value [0 ] !== $ value [1 ]) {
67+ return sprintf ('Expected iterable value is different from subject value at index %s ' , $ index );
68+ }
69+ }
70+
71+ $ subjectValid = $ subject ->valid ();
72+ $ otherValid = $ other ->valid ();
73+
74+ if ($ subjectValid !== $ otherValid ) {
75+ if (true === $ subjectValid ) {
76+ return 'Expected iterable has more items than subject. ' ;
77+ }
78+
79+ return 'Expected iterable has lesser items than subject. ' ;
80+ }
81+
82+ return '' ;
83+ }
84+
4585 /**
4686 * @param iterable<TKey, T> $other
4787 */
@@ -52,11 +92,11 @@ protected function matches($other): bool
5292 [$ this ->subject , $ other ]
5393 );
5494
55- $ mi = new MultipleIterableAggregate ([ $ subject , $ other ], MultipleIterator:: MIT_NEED_ALL );
56-
57- $ index = 0 ;
95+ $ mi = new PackIterableAggregate (
96+ new MultipleIterableAggregate ([ $ subject , $ other ], MultipleIterator:: MIT_NEED_ALL )
97+ ) ;
5898
59- foreach ($ mi as $ key => $ value ) {
99+ foreach ($ mi as $ index => [ $ key , $ value] ) {
60100 if (0 !== $ this ->limit && $ index >= $ this ->limit ) {
61101 break ;
62102 }
@@ -68,8 +108,6 @@ protected function matches($other): bool
68108 if ($ value [0 ] !== $ value [1 ]) {
69109 return false ;
70110 }
71-
72- ++$ index ;
73111 }
74112
75113 if (0 === $ this ->limit ) {
0 commit comments