<?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);
$interceptor->getPrefixes(); $interceptor->getPrefixesPsr4(); }); }); describe("::unpatch()", function () { it("detaches the patched autoloader", function () { Interceptor::patch(['cachePath' => $this->cachePath]); $success = Interceptor::unpatch(); $actual = Interceptor::instance(); expect($success)->toBe(true); expect($actual)->toBe(null); }); it("returns `false` if there's no patched autoloader", function () { Interceptor::patch(['cachePath' => $this->cachePath]); Interceptor::unpatch(); $success = Interceptor::unpatch(); expect($success)->toBe(false); }); }); describe("::load()", function () { it("auto unpatch when loading an interceptor autoloader", function () { $interceptor = Interceptor::patch(['cachePath' => $this->cachePath]); $new = new Interceptor(['originalLoader' => $interceptor->originalLoader(), 'cachePath' => $this->cachePath]); Interceptor::load($new); expect(Interceptor::instance())->toBe($new); expect(Interceptor::instance())->not->toBe($interceptor); }); }); describe("::instance()", function () { it("returns the interceptor autoloader", function () { $interceptor = Interceptor::patch(['cachePath' => $this->cachePath]);