Kahlan\Jit\Interceptor::unpatch PHP Method

unpatch() public static method

Restore the original autoloader behavior.
public static unpatch ( )
    public static function unpatch()
    {
        if (!static::$_interceptor) {
            return false;
        }
        $interceptor = static::$_interceptor;
        $original = $interceptor->originalLoader();
        spl_autoload_register($original, true, true);
        $success = spl_autoload_unregister($interceptor->loader());
        static::$_interceptor = null;
        return $success;
    }

Usage Example

Example #1
0
<?php

namespace Kahlan\Spec\Suite\Plugin;

use Kahlan\Jit\Interceptor;
use Kahlan\QuitException;
use Kahlan\Plugin\Quit;
use Kahlan\Jit\Patcher\Quit as QuitPatcher;
use Kahlan\Spec\Fixture\Plugin\Quit\Foo;
describe("Quit", function () {
    /**
     * Save current & reinitialize the Interceptor class.
     */
    beforeAll(function () {
        $this->previous = Interceptor::instance();
        Interceptor::unpatch();
        $cachePath = rtrim(sys_get_temp_dir(), DS) . DS . 'kahlan';
        $include = ['Kahlan\\Spec\\'];
        $interceptor = Interceptor::patch(compact('include', 'cachePath'));
        $interceptor->patchers()->add('quit', new QuitPatcher());
    });
    /**
     * Restore Interceptor class.
     */
    afterAll(function () {
        Interceptor::load($this->previous);
    });
    describe("::enable()", function () {
        it("enables quit statements", function () {
            Quit::disable();
            expect(Quit::enabled())->toBe(false);
All Usage Examples Of Kahlan\Jit\Interceptor::unpatch