示例#1
0
 /**
  * The Constructor.
  *
  * @param array $config Possible options values are:
  *                    - `'driver'` _object_: the driver instance which will log the coverage data.
  *                    - `'path'`   _array_ : the path(s) which contain the code source files.
  *                    - `'base'`   _string_: the base path of the repo (default: `getcwd`).
  *                    - `'prefix'` _string_: some prefix to remove to get the real file path.
  */
 public function __construct($config = [])
 {
     $defaults = ['driver' => null, 'path' => [], 'include' => '*.php', 'exclude' => [], 'type' => 'file', 'skipDots' => true, 'leavesOnly' => false, 'followSymlinks' => true, 'recursive' => true, 'base' => str_replace(DIRECTORY_SEPARATOR, '/', getcwd())];
     $config += $defaults;
     if (Interceptor::instance()) {
         $config += ['prefix' => rtrim(Interceptor::instance()->cachePath(), DS)];
     } else {
         $config += ['prefix' => ''];
     }
     $this->_driver = $config['driver'];
     $this->_paths = (array) $config['path'];
     $this->_base = $config['base'];
     $this->_prefix = $config['prefix'];
     $files = Dir::scan($this->_paths, $config);
     foreach ($files as $file) {
         $this->_coverage[realpath($file)] = [];
     }
 }
示例#2
0
use ReflectionMethod;
use InvalidArgumentException;
use jit\Interceptor;
use jit\Patchers;
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 () {
示例#3
0
<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use filter\Filter;
use jit\Interceptor;
Filter::register('doctrine.exclude.annotations', function ($chain) {
    $extra = ['Doctrine\\Common\\Annotations\\Annotation'];
    $exclude = $this->args()->get('exclude');
    $exclude = is_array($exclude) ? $exclude + $extra : $extra;
    $this->args()->set('exclude', $exclude);
    return $chain->next();
});
Filter::register('doctrine.annotations.autoloader', function ($chain) {
    AnnotationRegistry::registerLoader(Interceptor::instance()->loader());
    return $chain->next();
});
Filter::apply($this, 'interceptor', 'doctrine.exclude.annotations');
Filter::apply($this, 'run', 'doctrine.annotations.autoloader');
示例#4
0
 /**
  * The default `'patcher'` filter.
  */
 protected function _patchers()
 {
     return Filter::on($this, 'patchers', [], function ($chain) {
         if (!($interceptor = Interceptor::instance())) {
             return;
         }
         $patchers = $interceptor->patchers();
         $patchers->add('substitute', new DummyClass(['namespaces' => ['spec\\']]));
         $patchers->add('pointcut', new Pointcut());
         $patchers->add('monkey', new Monkey());
         $patchers->add('rebase', new Rebase());
         $patchers->add('quit', new Quit());
     });
 }