Exemplo n.º 1
0
 public function setUp()
 {
     $this->root = vfsStream::setup('exampleDir');
     $this->root->addChild(vfsStream::newFile('foo')->withContent('{"bar":1}'));
     $this->fh = vfsStream::url('exampleDir/foo');
     $this->sut = new FileTransport($this->fh);
 }
 /**
  * test method to be used for iterating
  *
  * @test
  */
 public function iteration()
 {
     $dir = new vfsStreamDirectory('foo');
     $mockChild1 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
     $mockChild1->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $dir->addChild($mockChild1);
     $mockChild2 = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
     $mockChild2->expects($this->any())->method('getName')->will($this->returnValue('baz'));
     $dir->addChild($mockChild2);
     $dirIterator = $dir->getIterator();
     $this->assertEquals('bar', $dirIterator->key());
     $this->assertTrue($dirIterator->valid());
     $bar = $dirIterator->current();
     $this->assertSame($mockChild1, $bar);
     $dirIterator->next();
     $this->assertEquals('baz', $dirIterator->key());
     $this->assertTrue($dirIterator->valid());
     $baz = $dirIterator->current();
     $this->assertSame($mockChild2, $baz);
     $dirIterator->next();
     $this->assertFalse($dirIterator->valid());
     $this->assertNull($dirIterator->key());
     $this->assertNull($dirIterator->current());
     $dirIterator->rewind();
     $this->assertTrue($dirIterator->valid());
     $this->assertEquals('bar', $dirIterator->key());
     $bar2 = $dirIterator->current();
     $this->assertSame($mockChild1, $bar2);
 }
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->rootDirectory = vfsStream::newDirectory('/');
     $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app'));
     $dir = $this->rootDirectory->getChild('var/log/app');
     $dir->addChild(vfsStream::newDirectory('app1'));
     $dir->addChild(vfsStream::newDirectory('app2'));
     $dir->addChild(vfsStream::newDirectory('foo'));
 }
Exemplo n.º 4
0
 function setUp()
 {
     vfsStreamWrapper::register();
     $root = new vfsStreamDirectory('root');
     $root->addChild(new vfsStreamDirectory('template'));
     $root->addChild(new vfsStreamDirectory('scripts'));
     $root->addChild(new vfsStreamDirectory('target'));
     vfsStreamWrapper::setRoot($root);
     Generator::$template_path = vfsStream::url('root/template');
     Generator::$script_path = vfsStream::url('root/scripts');
     Generator::$nimble_root = vfsStream::url('root');
 }
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->fooURL = vfsStream::url('foo');
     $this->barURL = vfsStream::url('foo/bar');
     $this->baz1URL = vfsStream::url('foo/bar/baz1');
     $this->baz2URL = vfsStream::url('foo/baz2');
     $this->foo = new vfsStreamDirectory('foo');
     $this->bar = new vfsStreamDirectory('bar');
     $this->baz1 = vfsStream::newFile('baz1')->lastModified(300)->lastAccessed(300)->lastAttributeModified(300)->withContent('baz 1');
     $this->baz2 = vfsStream::newFile('baz2')->withContent('baz2')->lastModified(400)->lastAccessed(400)->lastAttributeModified(400);
     $this->bar->addChild($this->baz1);
     $this->foo->addChild($this->bar);
     $this->foo->addChild($this->baz2);
     $this->foo->lastModified(100)->lastAccessed(100)->lastAttributeModified(100);
     $this->bar->lastModified(200)->lastAccessed(100)->lastAttributeModified(100);
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot($this->foo);
 }
Exemplo n.º 6
0
 /**
  * can't write to file
  */
 public function testNoWrite()
 {
     $root = new vfsStreamDirectory('exampleDir');
     $file = $this->getMock('vfsStreamFile', array('write'), array('test.txt'));
     $file->setContent('notoverwritten');
     $file->expects($this->once())->method('write')->will($this->returnValue(false));
     $root->addChild($file);
     vfsStreamWrapper::setRoot($root);
     $example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
     $this->assertSame('could not write data', $example->writeData('testdata'));
     $this->assertTrue($root->hasChild('test.txt'));
     $this->assertSame('notoverwritten', $root->getChild('test.txt')->getContent());
 }
 /**
  * When testing for a nested path, verify that directory separators are respected properly
  * so that subdir1/subdir2 is not considered equal to subdir1Xsubdir2.
  *
  * @test
  * @group bug_24
  * @group regression
  */
 public function explicitTestForSeparatorWithNestedPaths_Bug_24()
 {
     $mockChild = $this->getMock('org\\bovigo\\vfs\\vfsStreamContent');
     $mockChild->expects($this->any())->method('getType')->will($this->returnValue(vfsStreamContent::TYPE_FILE));
     $mockChild->expects($this->any())->method('getName')->will($this->returnValue('bar'));
     $subdir1 = new vfsStreamDirectory('subdir1');
     $this->dir->addChild($subdir1);
     $subdir2 = new vfsStreamDirectory('subdir2');
     $subdir1->addChild($subdir2);
     $subdir2->addChild($mockChild);
     $this->assertTrue($this->dir->hasChild('subdir1'), "Level 1 path with separator exists");
     $this->assertTrue($this->dir->hasChild('subdir1/subdir2'), "Level 2 path with separator exists");
     $this->assertTrue($this->dir->hasChild('subdir1/subdir2/bar'), "Level 3 path with separator exists");
     $this->assertFalse($this->dir->hasChild('subdir1.subdir2'), "Path with period does not exist");
     $this->assertFalse($this->dir->hasChild('subdir1.subdir2/bar'), "Nested path with period does not exist");
 }
 public function testGetStrings_endToEnd_severalLanguageFiles()
 {
     $ruDir = new vfsStreamDirectory('ru');
     $faDir = new vfsStreamDirectory('fa');
     $ruFile = new vfsStreamFile('language.php');
     $ruFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_ru_original.php'));
     $ruDir->addChild($ruFile);
     $faFile = new vfsStreamFile('language.php');
     $faFile->setContent(file_get_contents(__DIR__ . '/fixtures/language_fa_original.php'));
     $faDir->addChild($faFile);
     $this->langDir->addChild($ruDir);
     $this->langDir->addChild($faDir);
     $obj = new Language_GetStrings(new Language_CollectFiles(), new Language_WriteFile_Factory(), array('baseDir' => vfsStream::url('root')));
     $obj->addFileType(new Language_FileType_Php());
     $obj->addFileType(new Language_FileType_Tpl());
     $obj->run();
     $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_ru_modified.php'), file_get_contents(vfsStream::url('root/lang/ru/language.php')));
     $this->assertEquals(file_get_contents(__DIR__ . '/fixtures/language_fa_modified.php'), file_get_contents(vfsStream::url('root/lang/fa/language.php')));
 }
Exemplo n.º 9
0
 /**
  * Prepare a virtual filesystem for testing.
  */
 protected function setUp()
 {
     // @codeCoverageIgnoreStart
     if (!$this->_started) {
         $config = parse_ini_file(dirname(__FILE__) . '/../../paths.ini', true);
         require_once $config['Opl'] . 'Opl/Class.php';
         Opl_Loader::register();
         $this->_started = true;
     }
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot($root = new vfsStreamDirectory('libs'));
     $root->addChild(new vfsStreamDirectory('Foo'));
     $root->addChild(new vfsStreamDirectory('Bar'));
     $root->addChild(new vfsStreamDirectory('Joe'));
     $root->addChild(new vfsStreamDirectory('NewLib'));
     $root->addChild(new vfsStreamDirectory('Opl'));
     $root->addChild($this->_createFile('Bar.php', 'BAR.PHP'));
     // Contents of Opl/
     $root->getChild('Opl')->addChild(vfsStream::newFile('Test.php')->withContent(''));
     // Contents of NewLib/
     $root->getChild('NewLib')->addChild($this->_createFile('Class.php', 'NEWLIB/CLASS.PHP'));
     $root->getChild('NewLib')->addChild($this->_createFile('Foo.php', 'NEWLIB/FOO.PHP'));
     // Contents of Joe/
     $root->getChild('Joe')->addChild($this->_createFile('Class.php', 'JOE/CLASS.PHP'));
     $root->getChild('Joe')->addChild($this->_createFile('Foo.php', 'JOE/FOO.PHP'));
     $root->getChild('Joe')->addChild($this->_createFile('Bar.php', 'JOE/BAR.PHP'));
     $root->getChild('Joe')->addChild($this->_createFile('Exception.php', 'JOE/EXCEPTION.PHP'));
     $root->getChild('Joe')->addChild(new vfsStreamDirectory('Foo'));
     $root->getChild('Joe/Foo')->addChild($this->_createFile('Exception.php', 'JOE/FOO/EXCEPTION.PHP'));
     // Contents of Bar/
     $root->getChild('Bar')->addChild($this->_createFile('Class.php', 'BAR/CLASS.PHP'));
     // Contents of Foo/
     $root->getChild('Foo')->addChild($this->_createFile('Bar.php', 'FOO/BAR.PHP'));
     $root->getChild('Foo')->addChild($this->_createFile('Class.php', 'FOO/CLASS.PHP'));
     // @codeCoverageIgnoreStop
 }
Exemplo n.º 10
0
 private function createFile($path, $content)
 {
     $file = vfsStream::newFile($path);
     $file->setContent($content);
     $this->workDir->addChild($file);
 }
 /**
  * set up test environment
  */
 public function setUp()
 {
     $this->rootDirectory = vfsStream::newDirectory('/');
     $this->rootDirectory->addChild(vfsStream::newDirectory('var/log/app'));
 }