If the name contains slashes, a new directory structure will be created.
The returned directory will always be the parent directory of this
directory structure.
public static newDirectory ( string $name, integer $permissions = null ) : |
||
$name | string | name of directory to create |
$permissions | integer | permissions of directory to create |
return |
/** * @test */ public function visitDirectoryWritesDirectoryNameToStream() { $output = vfsStream::newFile('foo.txt')->at(vfsStream::setup()); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitDirectory(vfsStream::newDirectory('baz'))); $this->assertEquals("- baz\n", $output->getContent()); }
/** * @expectedException \RuntimeException * @expectedExceptionMessage returned an empty value */ public function testGenerateUnixRandomThrowsExceptionWhenRandomEmpty() { vfsStream::setup('root'); vfsStream::newDirectory('dev')->at(vfsStreamWrapper::getRoot()); vfsStream::newFile('urandom')->at(vfsStreamWrapper::getRoot()->getChild('dev')); $this->_stringGenerator->generateFromUnixRandom(10, vfsStream::url('root') . '/dev/urandom'); }
public function testDirectoryNonReadable() { $url = vfsStream::newDirectory('test', 00)->at($this->_root)->url(); $validator = new FileReadable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(array(FileReadable::FILE => "'{$url}' ist keine Datei oder nicht zugänglich"), $validator->getMessages()); }
protected function setUp() { $this->basePath = vfsStream::setup(); $this->basePath->addChild(vfsStream::newDirectory('project')); $this->basePath->addChild(vfsStream::newDirectory('hooks')); $this->basePath->addChild(vfsStream::newDirectory('.git/hooks')); }
protected function setFileSystem() { vfsStreamWrapper::register(); $root = vfsStream::newDirectory('build'); vfsStreamWrapper::setRoot($root); return $root; }
public function testVirtualizeCanAcceptVfsContentInstances() { $this->virtualSystem->virtualize(['test', vfsStream::newFile('test2'), vfsStream::newDirectory('testDir')]); $this->assertEquals(3, $this->virtualSystem->getFileCount()); $this->assertInstanceOf(vfsStreamDirectory::class, $this->virtualSystem->getFileAtIndex(2)); $this->assertInstanceOf(vfsStreamFile::class, $this->virtualSystem->getFileAtIndex(1)); }
public function testInputFilterSaveValidDir() { $preferences = array('saveRawData' => '1', 'saveDir' => vfsStream::newDirectory('test', 0777)->at(vfsStream::setup('root'))->url(), 'saveFormat' => 'XML', 'saveOverwrite' => '0'); $this->_form->setValidationGroup('Preferences'); $this->_form->setData(array('Preferences' => $preferences)); $this->assertTrue($this->_form->isValid()); }
public function testDirectoryReadOnly() { $url = vfsStream::newDirectory('test', 00)->at($this->_root)->url(); $validator = new DirectoryWritable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(array(DirectoryWritable::WRITABLE => "Verzeichnis '{$url}' ist nicht schreibbar"), $validator->getMessages()); }
public function testDirectoryNonReadable() { $url = vfsStream::newDirectory('test', 00)->at($this->_root)->url(); $validator = new FileReadable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(FileReadable::FILE, key($validator->getMessages())); }
public function testDecodeInventoryActionInputNotFile() { $inputFile = vfsStream::newDirectory('test')->at(vfsStream::setup('root'))->url(); $this->dispatch($inputFile); $this->assertEquals(10, $this->getResponseStatusCode()); $this->assertConsoleOutputContains("Input file does not exist or is not readable.\n"); }
/** * Profile the code contained inside the closure, returning * an array of XHProf profiling information. Optionally * filtered by a set of regular expressions which the called * function/class must match for the result to be returned. * * Special note: the $flags default value is hardcoded to * avoid errors when xhprof is not loaded - instead, this * causes a graceful "test skipped". * * @param \Closure $closure A standard Closure that will execute exactly the code that will be profiled, nothing more. * @param array $methodMatchExpressions An array of PERL regular expressions to filter which methods' results are returned. * @param integer $flags Standard XHPROF flags for what gets profiled. Default excludes built-in functions and CPU/memory. * @param array $options Optional further options (second argument for xhprof_enable). * @return array */ protected function profileClosure(\Closure $closure, array $methodMatchExpressions = array(), $flags = 1, $options = array()) { if (!$this->isProfilingExtensionLoaded()) { $this->markTestSkipped('XHProf is not installed; test must be skipped'); } $folder = vfsStream::newDirectory('profiles'); $backup = ini_set('xhprof.output_dir', vfsStream::url('profiles')); xhprof_enable($flags, $options); $closure(); $profile = xhprof_disable(); ini_set('xhprof.output_dir', $backup); if (!empty($methodMatchExpressions)) { foreach ($profile as $methodIdentifier => $_) { $keep = FALSE; foreach ($methodMatchExpressions as $expression) { if (preg_match($expression, $methodIdentifier)) { $keep = TRUE; } } if (!$keep) { unset($profile[$methodIdentifier]); } } } return $profile; }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->object = new NlReader(); vfsStreamWrapper::register(); $root = vfsStream::newDirectory('tmp'); vfsStreamWrapper::setRoot($root); $this->file = vfsStream::newFile('items.csv', 0764)->withContent("73-ou-XW46\nApple\n1\na")->at($root); }
public function setUp() { $this->root = VFS::setup('root'); VFS::newDirectory('storage', 0777)->at($this->root); VFS::newDirectory('private', 0400)->at($this->root); $this->fileSystem = new LocalFileSystem(); $this->rootObject = Mockery::mock('FileSystem\\Root')->shouldIgnoreMissing(); }
protected function _before() { $wp = vfsStream::newDirectory('wp'); $wpLoadFile = vfsStream::newFile('wp-load.php'); $wpLoadFile->setContent('foo'); $wp->addChild($wpLoadFile); $this->wpLoadPath = $wp->url() . '/wp-load.php'; $this->system = $this->prophesize(System::class); }
protected function setFileSystem() { vfsStreamWrapper::register(); $root = vfsStream::newDirectory('build'); vfsStreamWrapper::setRoot($root); $packagesBuilder = new PackagesBuilder(new NullOutput(), vfsStream::url('build'), array('repositories' => array(array('type' => 'composer', 'url' => 'http://localhost:54715')), 'require' => array('vendor/name' => '*')), false); $packagesBuilder->dump(array($this->package)); return $root; }
public function testExtractPublicKeyToFileWriteError() { $root = vfsStream::newDirectory('test'); $root->addChild(vfsStream::newFile('test.key', 00)); vfsStreamWrapper::setRoot($root); $this->setExpectedException('RuntimeException', 'The public key file "vfs://test/test.key" could not be written:'); $key = $this->helper->createPrivateKey('test'); $this->helper->extractPublicKeyToFile('vfs://test/test.key', $key, 'test'); }
/** @test */ public function attachPhoto() { $pic = 'photo.jpg'; vfsStreamWrapper::register(); $root = vfsStream::newDirectory('pics'); vfsStreamWrapper::setRoot($root); vfsStream::newFile($pic)->at($root); $this->entry->attachPhoto(vfsStream::url('pics/' . $pic)); $this->assertTrue($this->entry->hasPhoto()); }
public function test_create_fail_dir_creation() { $folder = vfsStream::newDirectory('testFolder_fail', 00)->at($this->root); $tokenizer = $this->instantiateClass('testfilename.token', vfsStream::url('testDir/testFolder_fail/tokens'), $this->token_content, new Filesystem()); $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild($tokenizer->getRootTokenFolder())); $this->assertFalse($tokenizer->checkRoot()); $result = $tokenizer->create(); $this->assertEquals($result['errors'], 1); $this->assertEquals($result['message'], 'Failed to create "vfs://testDir/testFolder_fail/tokens".'); }
public function testCheckFailureMultipleUnwritableDirs() { $root = vfsStream::setup(); $unwritableDir1 = vfsStream::newDirectory('unwritabledir1', 00)->at($root); $unwritableDir2 = vfsStream::newDirectory('unwritabledir2', 00)->at($root); $object = new DirWritable(array($unwritableDir1->url(), $unwritableDir2->url())); $r = $object->check(); $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $r); $this->assertEquals('The following directories are not writable: vfs://root/unwritabledir1, vfs://root/unwritabledir2.', $r->getMessage()); }
/** * @expectedException Message\Cog\Config\Exception * @expectedExceptionMessage Config directory `vfs://config/dev/` is not readable */ public function testExceptionThrownWhenDirectoryNotReadable() { vfsStream::setup('config'); vfsStream::newDirectory('dev', 00)->at(vfsStreamWrapper::getRoot()); $env = new FauxEnvironment(); $env->set('dev'); $loader = new Loader(vfsStream::url('config'), $env); $registry = new NonLoadingRegistry($loader); $loader->load($registry); }
public function testFindDescriptorsPath() { $path = $this->root->url(); $protoc = 'protoc'; $plugin = './bin/protobuf-plugin'; $builder = new ProcessBuilder($plugin, $protoc); $paths = [$path . '/not-found', $path . '/found']; $builder->setDescriptorPaths($paths); $this->root->addChild(vfsStream::newDirectory('found')); $this->assertEquals($path . '/found', $this->invokeMethod($builder, 'findDescriptorsPath')); }
/** * Check if a resque bin file is in the bin folder, * but with a .php extension * * @covers \Fresque\Fresque::getResqueBinFile * @return void */ public function testGetResqueBinWithExtension() { $method = new \ReflectionMethod('\\Fresque\\Fresque', 'getResqueBinFile'); $method->setAccessible(true); $root = vfsStream::setup('resque'); $root->addChild(vfsStream::newDirectory('bin')); $root->getChild('bin')->addChild(vfsStream::newFile('resque.php')); $this->assertTrue($root->hasChild('bin')); $this->assertTrue($root->getChild('bin')->hasChild('resque.php')); $this->assertEquals('./bin/resque.php', $method->invoke($this->shell, vfsStream::url('resque'))); }
/** * Create a directory structure for us to work on */ private function createDirStructureForUnInstaller() { vfsStream::newFile('file1.txt')->at($this->root->getChild('source')); vfsStream::newFile('file1.txt')->at($this->root->getChild('destination')); vfsStream::newFile('file2.txt')->at($this->root->getChild('source')); vfsStream::newFile('file2.txt')->at($this->root->getChild('destination')); vfsStream::newDirectory('folder1')->at($this->root->getChild('source')); vfsStream::newDirectory('folder1')->at($this->root->getChild('destination')); vfsStream::newFile('file3.txt')->at($this->root->getChild('source/folder1')); vfsStream::newFile('file3.txt')->at($this->root->getChild('destination/folder1')); }
/** * @expectedException Symfony\Component\Console\Exception\InvalidArgumentException */ public function testExecutePathDoesNotExist() { $source_path = '/src/sources'; $vfs = vfsStream::setup($source_path); $dir = vfsStream::newDirectory($source_path); $dir->addChild(vfsStream::newFile('text.txt')->at($vfs)); $application = new Application(); $application->add(new TranspileCommand()); $command = $application->find('transpile'); $commandTester = new CommandTester($command); $commandTester->execute(array('command' => $command->getName(), 'path' => $dir->url() . '/foo', 'output' => $dir->url() . '/foo-out')); }
protected function setUp() { $root = vfsStream::setup('CryptLibTest'); //Setup Folders $core = vfsStream::newDirectory('Core')->at($root); $af = vfsStream::newDirectory('AbstractFactory')->at($core); // Create Files vfsStream::newFile('test.php')->at($af); vfsStream::newFile('Some234Foo234Bar98Name.php')->at($af); vfsStream::newFile('Invalid.csv')->at($af); vfsStream::newFile('badlocation.php')->at($core); }
public function testNominalCase() { vfsStreamWrapper::register(); $root = vfsStream::newDirectory('build'); vfsStreamWrapper::setRoot($root); $webBuilder = new WebBuilder(new NullOutput(), vfsStream::url('build'), array(), false); $webBuilder->setRootPackage($this->rootPackage); $packages = array(new Package('vendor/name', '1.0.0.0', '1.0')); $webBuilder->dump($packages); $html = $root->getChild('build/index.html')->getContent(); $this->assertRegExp('/<h3 id="vendor\\/name">vendor\\/name<\\/h3>/', $html); }
/** * {@inheritdoc} */ public function setUp() { // Mock the existence of JSON definitions on the filesystem. $root = vfsStream::setup('resources'); $directory = vfsStream::newDirectory('tax_type')->at($root); foreach ($this->taxTypes as $id => $definition) { $filename = $id . '.json'; vfsStream::newFile($filename)->at($directory)->setContent(json_encode($definition)); } $zoneRepository = $this->getZoneRepository(); $this->taxTypeRepository = new TaxTypeRepository('vfs://resources/', $zoneRepository); }
protected function setUp() { $this->configMock = \Mockery::mock('\\JHM\\ConfigInterface'); $root = \org\bovigo\vfs\vfsStream::setup('server'); $datadir = \org\bovigo\vfs\vfsStream::newDirectory('data')->at($root); $storagedir = \org\bovigo\vfs\vfsStream::newDirectory('data')->at($datadir); $logdir = \org\bovigo\vfs\vfsStream::newDirectory('logs')->at($storagedir); $this->logfile = \org\bovigo\vfs\vfsStream::newFile('jhm-system.log')->at($logdir); $this->configMock->shouldReceive('getStorage')->with('logs')->once()->andReturn($logdir->url() . '/')->byDefault(); $this->configMock->shouldReceive('get')->with('loggingEnabled')->andReturn(true)->byDefault(); $this->obj = new \JHM\Logger($this->configMock); }
/** * Method: getEandomTranslation * When: a translation is missing a key * Should: throw exception */ public function testGetRandomTranslationFileIsMissingAKeyThrowException() { /** @var vfsStreamDirectory $rootDir */ $rootDir = vfsStream::newDirectory('rootDir'); vfsStreamWrapper::setRoot($rootDir); /** @var vfsStreamFile $file */ $file = vfsStream::newFile(self::TEST_FILENAME); $file->open(); $file->write(self::TEST_MISSING_KEY_TRANSLATIONS_JSON); $rootDir->addChild($file); $this->setExpectedException('Exception', 'Error. Language file is not found or is invalid. File: vfs://rootDir/' . self::TEST_FILENAME); $translation = $this->sut->getRandomTranslation(vfsStream::url('rootDir' . DIRECTORY_SEPARATOR . self::TEST_FILENAME)); }
/** * Проверяем работу предохранителя в рекурсивном удалении каталогов * * Явно нарушаем условия успешного выполнения метода, ожидаем исключение. При этом удаление не должно быть * выполнено. */ public function test_fuse_removeDir() { $this->expectException(FSException::class); $dirLevel4 = vfsStream::newDirectory('level4')->at($this->root->getChild('level1/level2/level3')); vfsStream::newFile('level4.txt')->withContent('level 4 from [delIt/], but 5 from the root path')->at($dirLevel4); $deepestChild = 'level1/level2/level3/level4/level4.txt'; $this->assertTrue($this->root->hasChild($deepestChild), 'Проверка предохранителя. Структура каталогов и файлов создана'); FS::removeDir($this->rootPath . '/level1', 3); $this->assertTrue($this->root->hasChild($deepestChild), 'Проверка предохранителя. Реальная вложенность больше заданной. Удаление не выполнено'); FS::removeDir($this->rootPath, 5); // от корня вложенность - 5, превышает допустимый максимум $this->assertTrue($this->root->hasChild($deepestChild), 'Проверка предохранителя. Требуемая вложенность больше максимально допустимой. Удаление не выполнено'); }