scan() public static method

Scans one or many directories for files.
public static scan ( array | string $path, array $options = [] ) : array
$path array | string Path or paths to scan.
$options array Scanning options. Possible values are: -`'iterator'` _integer_ : The iterator mode. -`'skipDots'` _boolean_ : Keeps '.' and '..' if `true`. -`'leavesOnly'` _boolean_ : Keeps only leaves if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. -`'recursive'` _boolean_ : Scans recursively if `true`. -`'include'` _string|array_: An array of includes. -`'exclude'` _string|array_: An array of excludes. -`'type'` _string|array_: An array of types.
return array
Beispiel #1
0
 /**
  * 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;
         }
     });
 }
Beispiel #2
0
 /**
  * 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;
         }
     });
 }
Beispiel #3
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' => 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)] = [];
     }
 }
Beispiel #4
0
                 expect(file_exists($this->tmpDir . $target))->toBe(true);
             }
         }
     });
     it("throws an exception if the destination directory doesn't exists", function () {
         $closure = function () {
             Dir::copy('spec/Fixture/Dir', 'Unexisting/Folder');
         };
         expect($closure)->toThrow(new Exception("Unexisting destination path `Unexisting/Folder`."));
     });
 });
 describe("::remove()", function () {
     it("removes a directory recursively", function () {
         $this->tmpDir = Dir::tempnam(sys_get_temp_dir(), 'spec');
         Dir::copy('spec/Fixture/Dir', $this->tmpDir);
         $paths = Dir::scan('spec/Fixture/Dir');
         Dir::remove($this->tmpDir);
         foreach ($paths as $path) {
             $target = preg_replace('~^spec~', '', $path);
             expect(file_exists($this->tmpDir . $target))->toBe(false);
         }
         expect(file_exists($this->tmpDir))->toBe(false);
     });
 });
 describe("::make()", function () {
     beforeEach(function () {
         $this->umask = umask(0);
         $this->tmpDir = Dir::tempnam(sys_get_temp_dir(), 'spec');
     });
     afterEach(function () {
         Dir::remove($this->tmpDir, ['recursive' => true]);