File tree Expand file tree Collapse file tree 2 files changed +26
-12
lines changed
Expand file tree Collapse file tree 2 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 99 *
1010 * - `Condition('self::processExecutionEnabled()')`
1111 * - `Condition(assert: 'function_exists("bcadd")')`
12+ * - `Condition(assert: fn() => PHP_VERSION_ID >= 80500)`
1213 *
1314 * @test test.unittest.ConditionTest
1415 */
@@ -27,14 +28,17 @@ public function __construct($assert) {
2728 * @return iterable
2829 */
2930 public function assertions (Context $ context ) {
30- $ assertion = $ this ->assert instanceof Closure
31- ? $ this ->assert
32- : $ context ->type ->evaluate ("fn() => {$ this ->assert }; " )
33- ;
31+ if ($ this ->assert instanceof Closure) {
32+ $ string = '<function()> ' ;
33+ $ assertion = $ this ->assert ;
34+ } else {
35+ $ string = (string )$ this ->assert ;
36+ $ assertion = $ context ->type ->evaluate ("fn() => {$ this ->assert }; " );
37+ }
3438
3539 yield new Assertion (
36- $ assertion ->bindTo ($ context ->instance , $ context ->type ->literal ())-> __invoke (),
37- new Verify ($ this -> assert )
40+ $ assertion ->bindTo ($ context ->instance , $ context ->type ->literal ())(),
41+ new Verify ($ string )
3842 );
3943 }
4044}
Original file line number Diff line number Diff line change 33use lang \Reflection ;
44use test \execution \Context ;
55use test \verify \Condition ;
6- use test \{Assert , Test , Values };
6+ use test \{Assert , Test };
77
88class ConditionTest {
99
@@ -29,11 +29,13 @@ public function can_create() {
2929 }
3030
3131 #[Test]
32- public function success () {
33- Assert::that (new Condition ('true ' ))
34- ->mappedBy ([$ this , 'failures ' ])
35- ->isNull ()
36- ;
32+ public function success_string () {
33+ Assert::that (new Condition ('true ' ))->mappedBy ([$ this , 'failures ' ])->isNull ();
34+ }
35+
36+ #[Test]
37+ public function success_closure () {
38+ Assert::that (new Condition (fn () => true ))->mappedBy ([$ this , 'failures ' ])->isNull ();
3739 }
3840
3941 #[Test]
@@ -44,6 +46,14 @@ public function failure_includes_assertion_expression() {
4446 ;
4547 }
4648
49+ #[Test]
50+ public function failure_includes_assertion_string () {
51+ Assert::that (new Condition (fn () => false ))
52+ ->mappedBy ([$ this , 'failures ' ])
53+ ->isEqualTo ('Failed verifying <function()> ' )
54+ ;
55+ }
56+
4757 #[Test]
4858 public function failure_can_access_context_scope () {
4959 Assert::that (new Condition ('self::verify() ' ))
You can’t perform that action at this time.
0 commit comments