55namespace Testo \Assert \Internal \Assertion \Traits ;
66
77use Testo \Assert \State \AssertException ;
8- use Testo \Assert \StaticState ;
8+ use Testo \Assert \State \ AssertTypeSuccess ;
99use Testo \Assert \Support ;
1010
1111/**
1212 * Contains assertion methods for iterable values.
1313 *
1414 * @property iterable $value
15+ * @property AssertTypeSuccess $parent
1516 */
1617trait IterableTrait
1718{
@@ -20,12 +21,12 @@ public function contains(mixed $needle, string $message = ''): self
2021 {
2122 foreach ($ this ->value as $ item ) {
2223 if ($ item === $ needle ) {
23- StaticState:: log ('Assert contains: ' . Support::stringify ($ needle ) . '. ' );
24- return new self ( $ this -> value ) ;
24+ $ this -> parent -> log ('Assert contains: ' . Support::stringify ($ needle ) . '. ' );
25+ return $ this ;
2526 }
2627 }
2728
28- StaticState:: fail (
29+ $ this -> parent -> fail (
2930 AssertException::fail (
3031 \sprintf (
3132 'Failed to assert that %s contains %s. ' ,
@@ -40,11 +41,11 @@ public function contains(mixed $needle, string $message = ''): self
4041 public function sameSizeAs (iterable $ expected , string $ message = '' ): self
4142 {
4243 if (self ::countIterable ($ this ->value ) === self ::countIterable ($ expected )) {
43- StaticState:: log ('Assert same size as: ' . Support::stringify ($ expected ) . '. ' );
44- return new self ( $ this -> value ) ;
44+ $ this -> parent -> log ('Assert same size as: ' . Support::stringify ($ expected ) . '. ' );
45+ return $ this ;
4546 }
4647
47- StaticState:: fail (
48+ $ this -> parent -> fail (
4849 AssertException::fail (
4950 \sprintf (
5051 'Failed to assert that iterable %s has the same number of elements as %s. ' ,
@@ -67,7 +68,7 @@ public function allOf(string $type, string $message = ''): self
6768 };
6869 foreach ($ this ->value as $ element ) {
6970 $ actualType = \strtolower (\get_debug_type ($ element ));
70- $ actualType === $ type or StaticState:: fail (
71+ $ actualType === $ type or $ this -> parent -> fail (
7172 AssertException::fail (
7273 \sprintf (
7374 'Failed to assert that all elements of iterable %s have type %s (found %s instead). ' ,
@@ -79,25 +80,25 @@ public function allOf(string $type, string $message = ''): self
7980 );
8081 }
8182
82- StaticState:: log (
83+ $ this -> parent -> log (
8384 \sprintf (
8485 'Assert all elements are of type %s. ' ,
8586 Support::stringify ($ type ),
8687 ),
8788 );
88- return new self ( $ this -> value ) ;
89+ return $ this ;
8990 }
9091
9192 #[\Override]
9293 public function hasCount (int $ expected ): self
9394 {
9495 $ count = self ::countIterable ($ this ->value );
9596 if ($ count === $ expected ) {
96- StaticState:: log ("Assert count: {$ count }. " );
97- return new self ( $ this -> value ) ;
97+ $ this -> parent -> log ("Assert count: {$ count }. " );
98+ return $ this ;
9899 }
99100
100- StaticState:: fail (
101+ $ this -> parent -> fail (
101102 AssertException::fail (
102103 \sprintf (
103104 'Failed to assert that %s has %d elements (found %d instead). ' ,
0 commit comments