kahlan\Matcher::get PHP Méthode

get() public static méthode

Returns registered matchers.
public static get ( string $name = null, string $target = '' ) : array
$name string The name of the matcher.
$target string An optionnal target class name.
Résultat array The registered matchers or a fully-namespaced class name if $name is not null.
    public static function get($name = null, $target = '')
    {
        if (!func_num_args()) {
            return static::$_matchers;
        }
        if ($target === true) {
            return isset(static::$_matchers[$name]) ? static::$_matchers[$name] : [];
        }
        if ($target === '') {
            if (isset(static::$_matchers[$name][''])) {
                return static::$_matchers[$name][''];
            }
            throw new Exception("Unexisting default matcher attached to `'{$name}'`.");
        }
        if (isset(static::$_matchers[$name][$target])) {
            return static::$_matchers[$name][$target];
        } elseif (isset(static::$_matchers[$name][''])) {
            return static::$_matchers[$name][''];
        }
        throw new Exception("Unexisting matcher attached to `'{$name}'` for `{$target}`.");
    }

Usage Example

Exemple #1
0
        });
        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::get