예제 #1
0
use kahlan\Arg;
use kahlan\jit\patcher\Pointcut;
use kahlan\plugin\Stub;
use kahlan\IncompleteException;
use kahlan\spec\fixture\plugin\pointcut\Foo;
use kahlan\spec\fixture\plugin\pointcut\SubBar;
describe("Stub", function () {
    /**
     * Save current & reinitialize the Interceptor class.
     */
    before(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('pointcut', new Pointcut());
    });
    /**
     * Restore Interceptor class.
     */
    after(function () {
        Interceptor::load($this->previous);
    });
    describe("::on()", function () {
        context("with an instance", function () {
            it("stubs a method", function () {
                $foo = new Foo();
                Stub::on($foo)->method('message')->andReturn('Good Bye!');
                expect($foo->message())->toBe('Good Bye!');
            });
예제 #2
0
파일: Kahlan.php 프로젝트: nurka1109/kahlan
 /**
  * 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')]);
     });
 }