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.
示例#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);
     });
示例#2
0
 /**
  * Returns a compatible matcher class name according to a passed actual value.
  *
  * @param  string $name   The name of the matcher.
  * @param  string $actual The actual value.
  * @return string         A matcher class name.
  */
 public function _matcher($matcherName, $actual)
 {
     if (!Matcher::exists($matcherName, true)) {
         throw new Exception("Unexisting matcher attached to `'{$matcherName}'`.");
     }
     $matcher = null;
     foreach (Matcher::get($matcherName, true) as $target => $value) {
         if (!$target) {
             $matcher = $value;
             continue;
         }
         if ($actual instanceof $target) {
             $matcher = $value;
         }
     }
     if (!$matcher) {
         throw new Exception("Unexisting matcher attached to `'{$matcherName}'` for `{$target}`.");
     }
     return $matcher;
 }