patch() public static méthode

Patch the autoloader to be intercepted by the current autoloader.
public static patch ( array $options = [] )
$options array Options for the interceptor autoloader.
Exemple #1
0
 /**
  * The default `'interceptor'` filter.
  */
 protected function _interceptor()
 {
     return Filter::on($this, 'interceptor', [], function ($chain) {
         Interceptor::patch(['loader' => [$this->autoloader(), 'loadClass'], 'include' => $this->args()->get('include'), 'exclude' => array_merge($this->args()->get('exclude'), ['Kahlan\\']), 'persistent' => $this->args()->get('persistent'), 'cachePath' => rtrim(realpath(sys_get_temp_dir()), DS) . DS . 'kahlan', 'clearCache' => $this->args()->get('cc')]);
     });
 }
Exemple #2
0
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);
            Quit::enable();
            expect(Quit::enabled())->toBe(true);
        });
Exemple #3
0
            Dir::remove($this->temp);
        });
        it("clears the cache", function () {
            $this->interceptor->clearCache();
            expect(file_exists($this->customCachePath))->toBe(false);
        });
        it("bails out if the cache has already been cleared", function () {
            $this->interceptor->clearCache();
            $this->interceptor->clearCache();
            expect(file_exists($this->customCachePath))->toBe(false);
        });
    });
    describe("->watch()/unwatch()", function () {
        it("add some file to be watched", function () {
            $this->temp = Dir::tempnam(null, 'cache');
            touch($this->temp . DS . 'watched1.php');
            touch($this->temp . DS . 'watched2.php');
            $watched = [$this->temp . DS . 'watched1.php', $this->temp . DS . 'watched2.php'];
            $this->interceptor = Interceptor::patch(['cachePath' => $this->cachePath]);
            $this->interceptor->watch($this->temp . DS . 'watched1.php');
            expect($this->interceptor->watched())->toBe([$watched[0]]);
            $this->interceptor->watch($this->temp . DS . 'watched2.php');
            expect($this->interceptor->watched())->toBe($watched);
            $this->interceptor->unwatch($this->temp . DS . 'watched1.php');
            expect($this->interceptor->watched())->toBe([$watched[1]]);
            $this->interceptor->unwatch($this->temp . DS . 'watched2.php');
            expect($this->interceptor->watched())->toBe([]);
            Dir::remove($this->temp);
        });
    });
});