@@ -25,6 +25,7 @@ class Expect extends ValidationChain
2525 protected Throwable |false |null $ except = null ;
2626 private ?TestCase $ testCase = null ;
2727 private ?array $ trace = null ;
28+ private bool $ valueHasBeenSet = false ;
2829
2930 /**
3031 * Static init validation chain
@@ -37,10 +38,49 @@ public static function value(mixed $value): self
3738 return new self ($ value );
3839 }
3940
41+ /**
42+ * Set a value
43+ *
44+ * @deprecated Use against() instead
45+ * @param mixed $value
46+ * @return self
47+ */
48+ public function setValue (mixed $ value ): self
49+ {
50+ $ this ->valueHasBeenSet = true ;
51+ return parent ::setValue ($ value );
52+ }
4053
54+ /**
55+ * Set the value to be validated
56+ *
57+ * @param mixed $value
58+ * @return self
59+ */
60+ public function against (mixed $ value ): self
61+ {
62+ $ this ->valueHasBeenSet = true ;
63+ return parent ::setValue ($ value );
64+ }
65+
66+ /**
67+ * Check if a value has been set
68+ *
69+ * @return bool
70+ */
71+ public function hasValueBeenSet (): bool
72+ {
73+ return $ this ->valueHasBeenSet ;
74+ }
75+
76+ /**
77+ * @deprecated Use against() instead
78+ * @param mixed $value
79+ * @return self
80+ */
4181 public function expect (mixed $ value ): self
4282 {
43- return $ this ->setValue ($ value );
83+ return $ this ->against ($ value );
4484 }
4585
4686 /**
@@ -136,7 +176,7 @@ public function assert(?string $description = null): void
136176 public function isThrowable (string |object |callable $ compare ): self
137177 {
138178 if ($ except = $ this ->getException ()) {
139- $ this ->setValue ($ except );
179+ $ this ->against ($ except );
140180 }
141181 /** @psalm-suppress PossiblyInvalidCast */
142182 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isClass ((string )$ compare ));
@@ -153,7 +193,7 @@ public function isThrowable(string|object|callable $compare): self
153193 public function hasThrowableMessage (string |callable $ compare ): self
154194 {
155195 if ($ except = $ this ->getException ()) {
156- $ this ->setValue ($ except ->getMessage ());
196+ $ this ->against ($ except ->getMessage ());
157197 }
158198 /** @psalm-suppress PossiblyInvalidCast */
159199 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isEqualTo ($ compare ));
@@ -170,7 +210,7 @@ public function hasThrowableMessage(string|callable $compare): self
170210 public function hasThrowableCode (int |callable $ compare ): self
171211 {
172212 if ($ except = $ this ->getException ()) {
173- $ this ->setValue ($ except ->getCode ());
213+ $ this ->against ($ except ->getCode ());
174214 }
175215 /** @psalm-suppress PossiblyInvalidCast */
176216 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isEqualTo ($ compare ));
@@ -188,7 +228,7 @@ public function hasThrowableSeverity(int|callable $compare): self
188228 {
189229 if ($ except = $ this ->getException ()) {
190230 $ value = method_exists ($ except , 'getSeverity ' ) ? $ except ->getSeverity () : 0 ;
191- $ this ->setValue ($ value );
231+ $ this ->against ($ value );
192232 }
193233 /** @psalm-suppress PossiblyInvalidCast */
194234 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isEqualTo ($ compare ));
@@ -205,7 +245,7 @@ public function hasThrowableSeverity(int|callable $compare): self
205245 public function hasThrowableFile (string |callable $ compare ): self
206246 {
207247 if ($ except = $ this ->getException ()) {
208- $ this ->setValue ($ except ->getFile ());
248+ $ this ->against ($ except ->getFile ());
209249 }
210250 /** @psalm-suppress PossiblyInvalidCast */
211251 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isEqualTo ($ compare ));
@@ -222,7 +262,7 @@ public function hasThrowableFile(string|callable $compare): self
222262 public function hasThrowableLine (int |callable $ compare ): self
223263 {
224264 if ($ except = $ this ->getException ()) {
225- $ this ->setValue ($ except ->getLine ());
265+ $ this ->against ($ except ->getLine ());
226266 }
227267 /** @psalm-suppress PossiblyInvalidCast */
228268 $ this ->validateExcept (__METHOD__ , $ compare , fn () => $ this ->isEqualTo ($ compare ));
@@ -253,7 +293,7 @@ protected function validateExcept(string $name, int|string|object|callable $comp
253293 }
254294
255295 if ($ this ->except === false ) {
256- $ this ->setValue (null );
296+ $ this ->against (null );
257297 }
258298 return $ this ;
259299 }
0 commit comments