Example #1
0
 protected function initializeVfs()
 {
     if (is_callable('vfsStream::create') === FALSE) {
         $this->markTestSkipped('vfsStream::create() does not exist');
     }
     \vfsStream::create($this->vfsContents);
 }
Example #2
0
 public function test_directory_map()
 {
     $structure = array('libraries' => array('benchmark.html' => '', 'database' => array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '0' => '', '.hiddenfile.txt' => ''));
     vfsStream::create($structure, $this->_test_dir);
     // test default recursive behavior
     $expected = array('libraries/' => array('benchmark.html', 'database/' => array('active_record.html', 'binds.html'), 'email.html', '0'));
     $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
     // test detection of hidden files
     $expected['libraries/'][] = '.hiddenfile.txt';
     $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), FALSE, TRUE));
     // test recursion depth behavior
     $this->assertEquals(array('libraries/'), directory_map(vfsStream::url('testDir'), 1));
 }
 public function test_directory_map()
 {
     $ds = DIRECTORY_SEPARATOR;
     $structure = array('libraries' => array('benchmark.html' => '', 'database' => array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', '0' => '', '.hiddenfile.txt' => ''));
     vfsStream::create($structure, $this->_test_dir);
     // is_dir(), opendir(), etc. seem to fail on Windows + vfsStream when there are trailing backslashes in directory names
     if (!is_dir(vfsStream::url('testDir') . DIRECTORY_SEPARATOR)) {
         $this->markTestSkipped();
         return;
     }
     // test default recursive behavior
     $expected = array('libraries' . $ds => array('benchmark.html', 'database' . $ds => array('active_record.html', 'binds.html'), 'email.html', '0'));
     $this->assertEquals($expected, directory_map(vfsStream::url('testDir')));
     // test detection of hidden files
     $expected['libraries' . $ds][] = '.hiddenfile.txt';
     $this->assertEquals($expected, directory_map(vfsStream::url('testDir'), 0, TRUE));
     // test recursion depth behavior
     $this->assertEquals(array('libraries' . $ds), directory_map(vfsStream::url('testDir'), 1));
 }
 /**
  * @test
  * @group  issue_20
  * @since  0.11.0
  */
 public function createCastsNumericDirectoriesToStringsWithRoot()
 {
     $root = vfsStream::setup();
     $this->assertSame($root, vfsStream::create(array(2011 => array('test.txt' => 'some content'))));
     $this->assertTrue($root->hasChild('2011'));
     $directory = $root->getChild('2011');
     $this->assertVfsFile($directory->getChild('test.txt'), 'some content');
 }
Example #5
0
 /**
  * Create VFS content
  *
  * @param	string	File name
  * @param	string	File content
  * @param	object	VFS directory object
  * @param	mixed	Optional subdirectory path or array of subs
  * @return	void
  */
 public function ci_vfs_create($file, $content = '', $root = NULL, $path = NULL)
 {
     // Check for array
     if (is_array($file)) {
         foreach ($file as $name => $content) {
             $this->ci_vfs_create($name, $content, $root, $path);
         }
         return;
     }
     // Assert .php extension if none given
     if (pathinfo($file, PATHINFO_EXTENSION) == '') {
         $file .= '.php';
     }
     // Build content
     $tree = array($file => $content);
     // Check for path
     $subs = array();
     if ($path) {
         // Explode if not array
         $subs = is_array($path) ? $path : explode('/', trim($path, '/'));
     }
     // Check for root
     if (!$root) {
         // Use base VFS root
         $root = $this->ci_vfs_root;
     }
     // Handle subdirectories
     while ($dir = array_shift($subs)) {
         // See if subdir exists under current root
         $dir_root = $root->getChild($dir);
         if ($dir_root) {
             // Yes - recurse into subdir
             $root = $dir_root;
         } else {
             // No - put subdirectory back and quit
             array_unshift($subs, $dir);
             break;
         }
     }
     // Create any remaining subdirectories
     if ($subs) {
         foreach (array_reverse($subs) as $dir) {
             // Wrap content in subdirectory for creation
             $tree = array($dir => $tree);
         }
     }
     // Create tree
     vfsStream::create($tree, $root);
 }
 /**
  * @test
  */
 public function getFolderListFailsIfDirectoryDoesNotExist()
 {
     $this->setExpectedException('InvalidArgumentException', '', 1314349666);
     $fixture = $this->createDriverFixture(array('basePath' => $this->getMountRootUrl()));
     \vfsStream::create(array($this->basedir => array('somefile' => '')));
     $fixture->getFolderList('somedir/');
 }
 /**
  * @test
  */
 public function directoryExitsTestUsingTrailingWinDirSeparator()
 {
     $structure = array('dir' => array('bar' => array()));
     vfsStream::create($structure, $this->root);
     $this->assertTrue(file_exists(vfsStream::url('root/') . 'dir\\'));
 }
 /**
  * @test
  * @group  issue_50
  */
 public function recursiveDirectoryIterationWithDotsDisabled()
 {
     vfsStream::disableDotfiles();
     vfsStream::setup();
     $structure = array('Core' => array('AbstractFactory' => array('test.php' => 'some text content', 'other.php' => 'Some more text content', 'Invalid.csv' => 'Something else'), 'AnEmptyFolder' => array(), 'badlocation.php' => 'some bad content'));
     $root = vfsStream::create($structure);
     $rootPath = vfsStream::url($root->getName());
     $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($rootPath), \RecursiveIteratorIterator::CHILD_FIRST);
     $pathes = array();
     foreach ($iterator as $fullFileName => $fileSPLObject) {
         $pathes[] = $fullFileName;
     }
     $this->assertEquals(array('vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'AbstractFactory' . DIRECTORY_SEPARATOR . 'test.php', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'AbstractFactory' . DIRECTORY_SEPARATOR . 'other.php', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'AbstractFactory' . DIRECTORY_SEPARATOR . 'Invalid.csv', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'AbstractFactory', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'AnEmptyFolder', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core' . DIRECTORY_SEPARATOR . 'badlocation.php', 'vfs://root' . DIRECTORY_SEPARATOR . 'Core'), $pathes);
 }
 /**
  * tests that a blank name for a block device throws an exception
  * @test
  * @expectedException org\bovigo\vfs\vfsStreamException
  */
 public function createWithEmptyName()
 {
     $structure = array('topLevel' => array('thisIsAFile' => 'file contents', '[]' => 'block contents'));
     $root = vfsStream::create($structure);
 }