Exemplo n.º 1
0
 /**
  * Recursively adds all the files in a directory to the test suite.
  *
  * @param string $directory The directory subtree to add tests from.
  * @return void
  */
 public function addTestDirectoryRecursive($directory = '.')
 {
     $Folder = new Folder($directory);
     $files = $Folder->tree(null, true, 'files');
     foreach ($files as $file) {
         if (substr($file, -4) === '.php') {
             $this->addTestFile($file);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Scan a directory for .php files and return the class names that
  * should be within them.
  *
  * @param string $dir The directory to read.
  * @return array The list of shell classnames based on conventions.
  */
 protected function _scanDir($dir)
 {
     $dir = new Folder($dir);
     $contents = $dir->read(true, true);
     if (empty($contents[1])) {
         return [];
     }
     $shells = [];
     foreach ($contents[1] as $file) {
         if (substr($file, -4) !== '.php') {
             continue;
         }
         $shells[] = substr($file, 0, -4);
     }
     return $shells;
 }
Exemplo n.º 3
0
 /**
  * Returns the full path of the file.
  *
  * @return string Full path to the file
  */
 public function pwd()
 {
     if ($this->getPath() === null) {
         $dir = $this->Folder->pwd();
         if (is_dir($dir)) {
             return $this->Folder->slashTerm($dir) . $this->name;
         }
     }
     return $this->getPath();
 }
Exemplo n.º 4
0
 /**
  * testIsAbsolute method
  *
  * @return void
  */
 public function testIsAbsolute()
 {
     $this->assertFalse(Folder::isAbsolute('path/to/file'));
     $this->assertFalse(Folder::isAbsolute('cake/'));
     $this->assertFalse(Folder::isAbsolute('path\\to\\file'));
     $this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
     $this->assertFalse(Folder::isAbsolute('\\path/to/file'));
     $this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
     $this->assertFalse(Folder::isAbsolute('notRegisteredStreamWrapper://example'));
     $this->assertFalse(Folder::isAbsolute('://example'));
     $this->assertTrue(Folder::isAbsolute('/usr/local'));
     $this->assertTrue(Folder::isAbsolute('//path/to/file'));
     $this->assertTrue(Folder::isAbsolute('C:\\cake'));
     $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
     $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
     $this->assertTrue(Folder::isAbsolute('\\\\vmware-host\\Shared Folders\\file'));
     $this->assertTrue(Folder::isAbsolute('http://www.example.com'));
 }
Exemplo n.º 5
0
 /**
  * Get the real path (taking ".." and such into account)
  *
  * @param string $path Path to resolve
  * @return string The resolved path
  */
 public function realpath($path)
 {
     $path = str_replace('/', DIRECTORY_SEPARATOR, trim($path));
     if (strpos($path, '..') === false) {
         if (!Folder::isAbsolute($path)) {
             $path = Folder::addPathElement($this->_path, $path);
         }
         return $path;
     }
     $parts = explode(DIRECTORY_SEPARATOR, $path);
     $newparts = [];
     $newpath = '';
     if ($path[0] === DIRECTORY_SEPARATOR) {
         $newpath = DIRECTORY_SEPARATOR;
     }
     while (($part = array_shift($parts)) !== null) {
         if ($part === '.' || $part === '') {
             continue;
         }
         if ($part === '..') {
             if (!empty($newparts)) {
                 array_pop($newparts);
                 continue;
             }
             return false;
         }
         $newparts[] = $part;
     }
     $newpath .= implode(DIRECTORY_SEPARATOR, $newparts);
     return Folder::slashTerm($newpath);
 }