kahlan\Matcher::exists PHP Method

exists() public static method

Checks if a matcher is registered.
public static exists ( string $name, string $target = '' ) : boolean
$name string The name of the matcher.
$target string An optional target class name.
return boolean Returns `true` if the matcher exists, `false` otherwise.
    public static function exists($name, $target = '')
    {
        if ($target === true) {
            return isset(static::$_matchers[$name]);
        }
        return isset(static::$_matchers[$name][$target]);
    }

Usage Example

Beispiel #1
0
         };
         expect($closure)->toThrow(new Exception("Unexisting default matcher attached to `'toHelloWorld'`."));
     });
     it("throws an exception when using an undefined matcher name for a specific class", function () {
         $closure = function () {
             Matcher::get('toHelloWorld', 'stdClass');
         };
         expect($closure)->toThrow(new Exception("Unexisting matcher attached to `'toHelloWorld'` for `stdClass`."));
     });
 });
 describe("::unregister()", function () {
     it("unregisters a matcher", function () {
         Matcher::register('toBeOrNotToBe', Double::classname(['extends' => 'Kahlan\\Matcher\\ToBe']));
         expect(Matcher::exists('toBeOrNotToBe'))->toBe(true);
         Matcher::unregister('toBeOrNotToBe');
         expect(Matcher::exists('toBeOrNotToBe'))->toBe(false);
     });
     it("unregisters all matchers", function () {
         expect(Matcher::get())->toBeGreaterThan(1);
         Matcher::unregister(true);
         Matcher::register('toHaveLength', 'Kahlan\\Matcher\\ToHaveLength');
         expect(Matcher::get())->toHaveLength(1);
     });
 });
 describe("::reset()", function () {
     it("unregisters all matchers", function () {
         expect(Matcher::get())->toBeGreaterThan(1);
         Matcher::reset();
         Matcher::register('toHaveLength', 'Kahlan\\Matcher\\ToHaveLength');
         expect(Matcher::get())->toHaveLength(1);
     });
All Usage Examples Of kahlan\Matcher::exists