kahlan\matcher\ToMatchEcho::match PHP Method

match() public static method

Checks that $actual echo the $expected regexp.
public static match ( Closure $actual, mixed $expected = null ) : boolean
$actual Closure The closure to run.
$expected mixed The expected string.
return boolean
    public static function match($actual, $expected = null)
    {
        $a = static::actual($actual);
        static::_buildDescription($a, $expected);
        if (is_callable($expected)) {
            return $expected($a);
        }
        return !!preg_match($expected, $a);
    }

Usage Example

Beispiel #1
0
                echo 'Hello World!';
            })->toMatchEcho('/^H(.*?)!$/');
        });
        it("passes if `'Hello World'` is not echoed", function () {
            expect(function () {
                echo 'Good Bye!';
            })->not->toMatchEcho('/^H(.*?)!$/');
        });
        it("passes if actual match the closure", function () {
            expect(function () {
                echo 'Hello World!';
            })->toMatchEcho(function ($actual) {
                return $actual === 'Hello World!';
            });
            expect(function () {
                echo 'Hello';
            })->not->toMatchEcho(function ($actual) {
                return $actual === 'Hello World!';
            });
        });
    });
    describe("::description()", function () {
        it("returns the description message", function () {
            ToMatchEcho::match(function () {
                echo 'Hello';
            }, "/Bye/");
            $actual = ToMatchEcho::description();
            expect($actual)->toBe(['description' => 'matches expected regex in echoed string.', 'params' => ["actual" => "Hello", "expected" => "/Bye/"]]);
        });
    });
});