/** * 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); }
/** * @test */ public function directoryCanBeCreatedUsingWinDirSeparator() { mkdir('vfs://root/dir\\bar\\foo', true, 0777); $this->assertTrue($this->root->hasChild('dir')); $this->assertTrue($this->root->getChild('dir')->hasChild('bar')); $this->assertTrue($this->root->getChild('dir/bar')->hasChild('foo')); }
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: should rename directory name as string internal * * @small */ public function testShouldRenameDirectoryNameAsStringInternal() { $dir = $this->rootDirectory->getChild('var/log/app'); $dir->addChild(vfsStream::newDirectory(80)); $child = $this->rootDirectory->getChild('var/log/app/80'); $child->rename(90); static::assertNotNull($this->rootDirectory->getChild('var/log/app/90')); }
/** * @test * @group rendering * @group small * @group dev */ public function test_setUnitValueCreatesDirForUnit() { // ARRANGE $unit = new \Render\Unit('unit-id', 'unit_module_id', 'unit name'); $fileCache = new FileBasedJsonCache(vfsStream::url('virtualTestCacheDir')); // ACT $fileCache->setUnitValue($unit, 'key', array('value' => '#test')); // ASSERT $this->assertTrue($this->root->hasChild('unit-id')); }
/** * visit a directory and process it * * @param vfsStreamDirectory $dir * @return vfsStreamStructureVisitor */ public function visitDirectory(vfsStreamDirectory $dir) { $this->current[$dir->getName()] = []; $tmp =& $this->current; $this->current =& $tmp[$dir->getName()]; foreach ($dir as $child) { $this->visit($child); } $this->current =& $tmp; return $this; }
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'); }
/** * 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()); }
public function testCreateConfigFound() { // Confirm mock filesystem contains config.php vfsStream::create(array('config.php' => 'config without secure data'), $this->root); $this->assertTrue($this->root->hasChild('config.php')); $output = array('Reviewing your Flaming Archer environment . . .', 'Found config.php.'); // Configure expectations foreach ($output as $index => $message) { $this->outputMock->expects($this->at($index))->method('write')->with($this->equalTo($message), $this->equalTo(true)); } $this->composerMock->expects($this->once())->method('getConfig')->will($this->returnValue($this->composerConfig)); $result = Config::create($this->event); }
/** * setting and retrieving owner group of a file * * @test * @group permissions */ public function group() { $this->assertEquals(vfsStream::getCurrentGroup(), $this->dir->getGroup()); $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::getCurrentGroup())); $this->assertSame($this->dir, $this->dir->chgrp(vfsStream::GROUP_USER_1)); $this->assertEquals(vfsStream::GROUP_USER_1, $this->dir->getGroup()); $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::GROUP_USER_1)); }
/** * 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); }
public function testUnlink() { $filePath = vfsStream::url('root/old_file.txt'); $fileSystem = new FileSystem(); $fileSystem->putContents($filePath, 'Old content'); $this->assertTrue($this->root->hasChild('old_file.txt')); $fileSystem->unlink($filePath); $this->assertFalse($this->root->hasChild('old_file.txt')); }
public function testWriteServiceProviderGuard() { $this->creator->writeServiceProvider($this->package, $this->rootdir->url(), true); $file = $this->rootdir->url() . '/src/' . $this->package->vendor . '/' . $this->package->name . '/' . $this->package->name . 'ServiceProvider.php'; $this->assertFileExists($file); $matches = array(); $this->assertTrue(preg_match('/namespace\\s+([^\\s;]+)/', file_get_contents($file), $matches) === 1); $namespace = $matches[1]; $this->assertEquals($this->package->vendor . '\\' . $this->package->name, $namespace); }
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'))); }
public function testTouch() { $dir = '/path/to/app'; $mFS = m::mock('Illuminate\\Filesystem\\Filesystem'); $mCmd = m::mock('Console\\BuildCommand'); $touches = [vfsStream::url('touchDir') . DIRECTORY_SEPARATOR . 'one.txt', vfsStream::url('touchDir') . DIRECTORY_SEPARATOR . 'two.txt']; $config = $this->getConfig(); $config['touch'] = $touches; foreach ($touches as $touchFile) { $mCmd->shouldReceive('comment')->once()->with("Touch", $touchFile); } $this->assertFalse($this->root->hasChild('one.txt')); $this->assertFalse($this->root->hasChild('two.txt')); $structure = new Structure($dir, $config, $mFS, $mCmd); $structure->touch(); $this->assertTrue($this->root->hasChild('one.txt')); $this->assertTrue($this->root->hasChild('two.txt')); }
/** * get composer.json files of the created packages * * @return array returns the path of the composer.json file */ private function getServiceProviderFiles() { return array('oldfashioned' => $this->rootdir->url() . '/vendor/old-fashioned/src/' . $this->oldfashioned->vendor . '/' . $this->oldfashioned->name . '/' . $this->oldfashioned->name . 'ServiceProvider.php', 'newpackage' => $this->rootdir->url() . '/vendor/new-package/src/' . preg_replace('/\\/+/', '/', str_replace('\\', '/', $this->newpackage->namespace) . '/') . $this->newpackage->name . 'ServiceProvider.php'); }
private function createFile($path, $content) { $file = vfsStream::newFile($path); $file->setContent($content); $this->workDir->addChild($file); }
/** * @test */ public function createDirectoryWithDifferentUmaskSetting() { vfsStream::umask(022); $directory = new vfsStreamDirectory('foo'); $this->assertEquals(0755, $directory->getPermissions()); }
/** * reset directory iteration * * @return bool */ public function dir_rewinddir() { return $this->dirIterator->rewind(); }
/** * @test */ public function shouldContainSubdirectoryApp2() { $this->assertTrue($this->rootDirectory->getChild('var/log/app')->hasChild('app2')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', $this->rootDirectory->getChild('var/log/app')->getChild('app2')); }
/** * 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 }
/** * @test * @author Sebastian Kurfürst <*****@*****.**> */ public function pathToPartialIsResolvedCorrectly() { $this->markTestSkipped('Needs to be finished'); vfsStreamWrapper::register(); mkdir('vfs://MyTemplates'); file_put_contents('vfs://MyTemplates/MyCoolAction.html', 'contentsOfMyCoolAction'); $mockRootDirectory = vfsStreamDirectory::create('ExamplePackagePath/Resources/Private/Partials'); $mockRootDirectory->getChild('Resources/Private/Partials')->addChild('Partials'); vfsStreamWrapper::setRoot($mockRootDirectory); $this->getAccessibleMock('Tx_Fluid_Core_Parser_TemplateParser', array(''), array(), '', FALSE); }
/** * @test * @author Sebastian Kurfürst <*****@*****.**> */ public function pathToPartialIsResolvedCorrectly() { $this->markTestSkipped('Needs proper implementation.'); $mockRequest = $this->getMock('F3\\FLOW3\\MVC\\Request', array('getControllerPackageKey', '')); $mockRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('DummyPackageKey')); $mockControllerContext = $this->getMock('F3\\FLOW3\\MVC\\Controller\\Context', array('getRequest')); $mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($mockRequest)); $mockPackage = $this->getMock('F3\\FLOW3\\Package\\PackageInterface', array('getPackagePath')); $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue('/ExamplePackagePath/')); $mockPackageManager = $this->getMock('F3\\FLOW3\\Package\\PackageManagerInterface', array('getPackage')); $mockPackageManager->expects($this->any())->method('getPackage')->with('DummyPackageKey')->will($this->returnValue($mockPackage)); \vfsStreamWrapper::register(); $mockRootDirectory = vfsStreamDirectory::create('ExamplePackagePath/Resources/Private/Partials'); $mockRootDirectory->getChild('Resources/Private/Partials')->addChild('Partials'); \vfsStreamWrapper::setRoot($mockRootDirectory); $this->getMock($this->buildAccessibleProxy('F3\\Fluid\\Core\\Parser\\TemplateParser'), array(''), array(), '', FALSE); }