Kahlan\Plugin\Monkey::reset PHP Method

reset() public static method

Clears the registered references.
public static reset ( string $source = null )
$source string A fully-namespaced reference string or `null` to clear all.
    public static function reset($source = null)
    {
        if ($source === null) {
            static::$_registered = [];
            return;
        }
        unset(static::$_registered[$source]);
    }

Usage Example

Beispiel #1
0
            $patch->toBe(new DateTime('@123'), new DateTime('@456'));
            expect($mon->datetime()->getTimestamp())->toBe(123);
            expect($mon->datetime()->getTimestamp())->toBe(456);
        });
        it("patches a function", function () {
            $mon = new Mon();
            Monkey::patch('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand', 'Kahlan\\Spec\\Suite\\Plugin\\myrand');
            expect($mon->rand(0, 100))->toBe(101);
        });
        it("patches a class", function () {
            $mon = new Mon();
            Monkey::patch('Kahlan\\Util\\Text', 'Kahlan\\Spec\\Mock\\Plugin\\Monkey\\MyString');
            expect($mon->dump((object) 'hello'))->toBe('myhashvalue');
        });
        it("can unpatch a monkey patch", function () {
            $mon = new Mon();
            Monkey::patch('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand', 'Kahlan\\Spec\\Suite\\Plugin\\myrand');
            expect($mon->rand(0, 100))->toBe(101);
            Monkey::reset('Kahlan\\Spec\\Fixture\\Plugin\\Monkey\\rand');
            expect($mon->rand(0, 100))->toBe(50);
        });
        it("throws an exception with trying to patch an unsupported functions or core langage statements", function () {
            $closure = function () {
                Monkey::patch('func_get_args', function () {
                    return [];
                });
            };
            expect($closure)->toThrow(new Exception('Monkey patching `func_get_args()` is not supported by Kahlan.'));
        });
    });
});
All Usage Examples Of Kahlan\Plugin\Monkey::reset