/** * The default `'load'` filter. */ protected function _load() { return Filter::on($this, 'load', [], function ($chain) { $files = Dir::scan($this->args()->get('spec'), ['include' => $this->args()->get('pattern'), 'exclude' => '*/.*', 'type' => 'file']); foreach ($files as $file) { require $file; } }); }
/** * 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' => 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)] = []; } }
/** * The default `'load'` filter. */ protected function _load() { return Filter::on($this, 'load', [], function ($chain) { $specDirs = $this->commandLine()->get('spec'); foreach ($specDirs as $dir) { if (!file_exists($dir)) { fwrite(STDERR, "ERROR: unexisting `{$dir}` directory, use --spec option to set a valid one (ex: --spec=tests).\n"); exit(-1); } } $files = Dir::scan($specDirs, ['include' => $this->commandLine()->get('pattern'), 'exclude' => '*/.*', 'type' => 'file']); foreach ($files as $file) { require $file; } }); }
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); }); }); });
$stat = stat($path); $mode = $stat['mode'] & 0777; expect($mode)->toBe(0755); }); it("creates a nested directory with a specific mode", function () { $path = $this->tmpDir . '/My/Nested/Directory'; $actual = Dir::make($path, ['mode' => 0777]); expect($actual)->toBe(true); expect(file_exists($path))->toBe(true); $stat = stat($path); $mode = $stat['mode'] & 0777; expect($mode)->toBe(0777); }); it("creates multiple nested directories in a single call", function () { $paths = [$this->tmpDir . '/My/Nested/Directory', $this->tmpDir . '/Sub/Nested/Directory']; $actual = Dir::make($paths); expect($actual)->toBe(true); foreach ($paths as $path) { expect(file_exists($path))->toBe(true); } }); }); describe("::tempnam()", function () { it("uses the system temp directory by default", function () { $dir = Dir::tempnam(null, 'spec'); $temp = sys_get_temp_dir(); expect($this->normalize($dir))->toMatch('~' . $this->normalize($temp) . '/spe~'); Dir::remove($dir); }); }); });