create() public static method

Assumed $structure contains an array like this: 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', ) ) the resulting directory tree will look like this:
baseDir
\- Core
 |- badlocation.php
 |- AbstractFactory
 | |- test.php
 | |- other.php
 | \- Invalid.csv
 \- AnEmptyFolder
Arrays will become directories with their key as directory name, and strings becomes files with their key as file name and their value as file content. If no baseDir is given it will try to add the structure to the existing root directory without replacing existing childs except those with equal names.
See also: https://github.com/mikey179/vfsStream/issues/14
See also: https://github.com/mikey179/vfsStream/issues/20
Since: 0.10.0
public static create ( array $structure, vfsStreamDirectory $baseDir = null ) : vfsStreamDirectory
$structure array directory structure to add under root directory
$baseDir vfsStreamDirectory base directory to add structure to
return vfsStreamDirectory
コード例 #1
0
 /**
  * @param $csvContent
  * @return string
  */
 protected function setUpVirtualFileAndGetPath($csvContent)
 {
     $structure = array('directory' => array('my_file.csv' => $csvContent));
     vfsStream::setup();
     vfsStream::create($structure);
     return vfsStream::url('root/directory/my_file.csv');
 }
コード例 #2
0
 /**
  * Tests success case for loading a valid and readable YAML file.
  *
  * @covers ::load
  */
 public function testLoad()
 {
     $initialContent = ['hello' => 'world'];
     $ymlContent = Yaml::dump($initialContent);
     vfsStream::create(['file1' => $ymlContent], $this->root);
     $this->assertEquals($initialContent, (new YamlFileLoader())->load(vfsStream::url('test/file1')));
 }
コード例 #3
0
ファイル: BaseTestCase.php プロジェクト: khanhdeux/typo3test
 protected function initializeVfs()
 {
     if (is_callable('org\\bovigo\\vfs\\vfsStream::create') === FALSE) {
         $this->markTestSkipped('vfsStream::create() does not exist');
     }
     vfsStream::create($this->vfsContents);
 }
コード例 #4
0
 public function testLoad()
 {
     $initialContent = array('some content');
     vfsStream::create(array('file1' => json_encode($initialContent)), $this->root);
     $content = (new JsonFileLoader())->load(vfsStream::url('test/file1'));
     $this->assertEquals($initialContent, $content);
 }
コード例 #5
0
 protected function setUp()
 {
     $this->loader = new LayoutLoader();
     $this->fileSystem = Stream::setup('root');
     $files = array('handle_one_file1.php' => sprintf('<?php %s', '$this->addItem(new EcomDev_LayoutCompiler_Layout_Item_Remove("handle_one_block_one"));'), 'handle_one_file2.php' => sprintf('<?php %s', implode("\n", array('$this->addItem(new EcomDev_LayoutCompiler_Layout_Item_Remove("handle_one_block_two"));', '$this->addItem($item = new EcomDev_LayoutCompiler_Layout_Item_Remove("handle_one_block_three"));', '$this->addItemRelation($item, "handle_one_block_three");'))), 'handle_two_file1.php' => sprintf('<?php %s', implode("\n", array('$this->addItem(new EcomDev_LayoutCompiler_Layout_Item_Remove("handle_two_block_one"));'))), 'handle_three_file1.php' => sprintf('<?php '), 'handle_three_file2.php' => sprintf('<?php '), 'handle_four_file1.php' => sprintf('<?php '));
     Stream::create($files, $this->fileSystem);
 }
コード例 #6
0
 public function testGetCommandsList()
 {
     $commandManager = $this->createCommandManager();
     $this->assertEquals([], $commandManager->getCommandsList());
     vfsStream::create(['foo.php' => '', 'bar.php' => '', 'baz' => ['baz.php' => '']], $this->commandsFolder);
     $this->assertEquals(['bar', 'baz', 'foo'], $commandManager->getCommandsList());
 }
コード例 #7
0
 public function testRecursiveTempDirectory()
 {
     vfsStream::create(array('recursive' => array('a' => array('1' => 'file', 'A' => array()), 'b' => array())), $this->root);
     $temp = new TempDirectory(vfsStream::url('root/recursive'), true);
     unset($temp);
     $this->assertFalse($this->root->hasChild('recursive'), "recursive dir and its contents must have been deleted");
 }
コード例 #8
0
 private function execute(array $fileStructure, array $options = []) : CommandTester
 {
     $fs = vfsStream::create($fileStructure, vfsStream::setup(getcwd()));
     $commandTester = new CommandTester($this->command);
     $commandTester->execute(array_merge(['command' => $this->command->getName(), 'path' => $fs->url()], $options));
     return $commandTester;
 }
コード例 #9
0
 /**
  * @param $fileContent
  * @param $expectedMetadataObjects
  * @param $expectedMetadataHandleObjects
  * 
  * @dataProvider dataProviderMetadataObjectsFromFile
  */
 public function testItLoadsMetaDataObjectsFromFile($fileContent, $expectedMetadataObjects, $expectedMetadataHandleObjects)
 {
     Stream::create(array('index_test_file.php' => $fileContent), $this->virtualDirectory);
     $this->index->setSavePath($this->virtualDirectory->url());
     $this->assertTrue($this->index->load(array('test' => 'file')));
     $this->assertAttributeEquals($expectedMetadataObjects, 'metadata', $this->index);
     $this->assertAttributeEquals($expectedMetadataHandleObjects, 'metadataByHandle', $this->index);
 }
コード例 #10
0
ファイル: TempFileTest.php プロジェクト: vube/php-filesystem
 private function createTempFile($file)
 {
     $url = vfsStream::url('root/' . $file);
     vfsStream::create(array($file => 'a temp file'), $this->root);
     $tempFile = new TempFile($url);
     // unused, we just want it to destruct after function returns
     $this->assertTrue($this->root->hasChild($file), "Expect we did create this file: {$file}");
 }
コード例 #11
0
 /**
  * @test
  */
 public function locate_should_return_correct_results()
 {
     vfsStream::setup();
     $root = vfsStream::create(['config' => ['config_file.yml' => 'CONTENT', 'config_file.php' => 'CONTENT', 'foo.txt' => 'CONTENT'], 'src' => ['AppBundle' => ['config' => ['configuration.yml' => 'CONTENT']]], 'web' => ['app.php' => 'CONTENT']]);
     $result = $this->getLocator()->locate($root->url(), '.yml');
     sort($result);
     $this->assertEquals([$root->url() . '/config/config_file.yml', $root->url() . '/src/AppBundle/config/configuration.yml'], $result);
 }
コード例 #12
0
 private function setupVfsStream()
 {
     $root = vfsStream::setup('root');
     vfsStream::create(['tmp' => ['file.txt' => 'foobar'], 'uploads' => ['image.png' => 'image']]);
     $this->sourceUrl = vfsStream::url('root/tmp/file.txt');
     $this->destUrl = vfsStream::url('root/uploads');
     $this->existingUrl = vfsStream::url('root/uploads/image.png');
 }
コード例 #13
0
ファイル: MockTest.php プロジェクト: ignaszak/cms
 /**
  *
  * @param array $structure
  * @return string
  */
 public static function mockFileSystem(array $structure) : string
 {
     if (empty(self::$vfsStreamRoot)) {
         self::$vfsStreamRoot = vfsStream::setup('mock');
     }
     vfsStream::create($structure, self::$vfsStreamRoot);
     return vfsStream::url('mock');
 }
コード例 #14
0
 protected function setUp()
 {
     vfsStream::setup('root');
     vfsStream::create(['uploads' => ['upload 0 contents', 'upload 1 contents', 'upload 2 contents', 'upload 3 contents', 'upload 4 contents']]);
     $this->files = [['tmp_name' => vfsStream::url('root/uploads/0')], ['tmp_name' => vfsStream::url('root/uploads/1')], ['tmp_name' => vfsStream::url('root/uploads/2')], [], ['tmp_name' => [vfsStream::url('root/uploads/3'), vfsStream::url('root/uploads/4')]]];
     is_uploaded_file('', [$this->files[0]['tmp_name'], $this->files[1]['tmp_name'], $this->files[4]['tmp_name'][0], $this->files[4]['tmp_name'][1]]);
     $this->assertFilesExist();
 }
コード例 #15
0
 protected static function createVirtualFiles($upload_data)
 {
     $name_corrected_upload_data = [];
     foreach ($upload_data as $k => $v) {
         $name_corrected_upload_data[str_replace(self::BASE_PATH, "", $k)] = $v;
     }
     // vfsStream::create will take a reference, not a copy.
     vfsStream::create(['uploads' => $name_corrected_upload_data]);
 }
コード例 #16
0
 protected function setUp()
 {
     require_once 'third_party/vfsstream/vendor/autoload.php';
     vfsStream::setup('uploads');
     vfsStream::create(['upload 0 contents', 'upload 1 contents', 'upload 2 contents']);
     $this->files = [['tmp_name' => vfsStream::url('uploads/0')], ['tmp_name' => vfsStream::url('uploads/1')], ['tmp_name' => vfsStream::url('uploads/2')], []];
     is_uploaded_file('', [$this->files[0]['tmp_name'], $this->files[1]['tmp_name']]);
     $this->assertFilesExist();
 }
コード例 #17
0
 /**
  * @test
  */
 public function detectMagento2InHtdocsSubfolder()
 {
     vfsStream::setup('root');
     vfsStream::create(array('htdocs' => array('app' => array('autoload.php' => '', 'bootstrap.php' => ''))));
     $helper = $this->getHelper();
     // vfs cannot resolve relative path so we do 'root/htdocs' etc.
     $helper->detect(vfsStream::url('root'), array(vfsStream::url('root/www'), vfsStream::url('root/public'), vfsStream::url('root/htdocs')));
     $this->assertEquals(vfsStream::url('root/htdocs'), $helper->getRootFolder());
     $this->assertEquals(\N98\Magento\Application::MAGENTO_MAJOR_VERSION_2, $helper->getMajorVersion());
 }
コード例 #18
0
 /**
  * @test
  * @dataProvider removeFirstInstallFileDataProvider
  */
 public function removeFirstInstallFile($structure, $expected)
 {
     $vfs = vfsStream::setup("root");
     vfsStream::create($structure, $vfs);
     /** @var $instance \TYPO3\CMS\Install\Service\EnableFileService|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface|\PHPUnit_Framework_MockObject_MockObject */
     $instance = $this->getAccessibleMock(\TYPO3\CMS\Install\Service\EnableFileService::class, array('dummy'), array(), '', FALSE);
     $instance->_setStatic('sitePath', 'vfs://root/');
     $instance->_call('removeFirstInstallFile');
     $this->assertEquals(array(), array_diff($expected, scandir('vfs://root/')));
 }
コード例 #19
0
 /**
  * @covers \Heystack\Core\DataObjectGenerate\DataObjectGenerator::process
  */
 public function testProcessDeleteFiles()
 {
     vfsStream::create(['cache' => ['CachedSomething.php' => 'test']], $this->root);
     $this->schemaService->expects($this->once())->method('getSchemas')->will($this->returnValue([]));
     $this->assertTrue(file_exists(vfsStream::url('root/cache/CachedSomething.php')));
     ob_start();
     $this->generator->process();
     ob_end_clean();
     $this->assertFalse(file_exists(vfsStream::url('root/cache/CachedSomething.php')));
 }
コード例 #20
0
 public function testGetTargetFiles()
 {
     vfsStream::setup();
     $structure = ['src' => ['1.php' => '', '2.php' => '', '3.csv' => ''], 'src1' => ['4.php' => '']];
     $root = vfsStream::create($structure);
     $rootPath = vfsStream::url($root->getName());
     $targets = getTargetFiles($rootPath);
     $this->assertEquals('vfs://root' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '1.php', $targets[0]);
     $this->assertEquals('vfs://root' . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . '2.php', $targets[1]);
     $this->assertEquals('vfs://root' . DIRECTORY_SEPARATOR . 'src1' . DIRECTORY_SEPARATOR . '4.php', $targets[2]);
 }
コード例 #21
0
 protected function setUp()
 {
     parent::setUp();
     $this->dataDir = realpath(dirname(__DIR__) . '/../../data');
     $this->root = vfsStream::setup('pdp');
     vfsStream::create(array('cache' => array()), $this->root);
     $this->cacheDir = vfsStream::url('pdp/cache');
     $this->listManager = new PublicSuffixListManager($this->cacheDir);
     $this->httpAdapter = $this->getMock('\\Pdp\\HttpAdapter\\HttpAdapterInterface');
     $this->listManager->setHttpAdapter($this->httpAdapter);
 }
コード例 #22
0
ファイル: FileSystemTest.php プロジェクト: aWEBoLabs/taxi
 /**
  * @covers ::unlink
  */
 public function testUnlink()
 {
     vfsStream::setup('dir');
     vfsStream::create(['test.txt' => 'asdf']);
     $uri = 'vfs://dir/test.txt';
     $this->fileSystem = $this->getMockBuilder('Drupal\\Core\\File\\FileSystem')->disableOriginalConstructor()->setMethods(['validScheme'])->getMock();
     $this->fileSystem->expects($this->once())->method('validScheme')->willReturn(TRUE);
     $this->assertFileExists($uri);
     $this->fileSystem->unlink($uri);
     $this->assertFileNotExists($uri);
 }
コード例 #23
0
 protected function setUp()
 {
     $this->root = vfsStream::setup('enum');
     vfsStream::create(['app' => ['config' => []], 'var' => ['cache' => []], 'src' => ['FooBundle' => ['Resources' => ['config' => ['enum.yml' => "foobar: test\\Enum\\Fixtures\\FooBarType"]], 'FooBundle.php' => '<?php class FooBundle {}'], 'BarBundle' => ['Resources' => ['config' => ['enum.yml' => "onetwo: test\\Enum\\Fixtures\\OneTwoType\nthreefour: test\\Enum\\Fixtures\\OneTwoType"]], 'BarBundle.php' => '<?php class BarBundle {}']]], $this->root);
     $this->extension = new EnumExtension();
     $this->container = new ContainerBuilder();
     $this->container->setParameter('kernel.root_dir', $this->root->getChild('app')->path());
     $this->container->setParameter('kernel.bundles', []);
     $this->container->setParameter('kernel.cache_dir', $this->root->getChild('var/cache')->path());
     $this->container->registerExtension($this->extension);
     $this->container->loadFromExtension($this->extension->getAlias());
 }
コード例 #24
0
ファイル: LameTest.php プロジェクト: b-b3rn4rd/phplame
 public function setUp()
 {
     parent::setUp();
     $structure = array('usr' => array('bin' => array()), 'tmp' => array('music' => array('wawfiles' => array('mp3' => array(), 'hello world.waw' => 'nice song', 'abc.waw' => 'bad song', 'put that cookie down.waw' => 'best song ever', "zed's dead baby.waw" => 'another cool song'))));
     $vfs = vfsStream::setup('root');
     vfsStream::create($structure, $vfs);
     vfsStream::newFile('usr/bin/lame', 0777)->at($vfs)->setContent('binary file');
     $this->filesystem = $vfs;
     $encoding = $this->getMockBuilder('\\Lame\\Settings\\Encoding\\NullEncoding')->getMock();
     $settings = $this->getMockBuilder('\\Lame\\Settings\\Settings')->setConstructorArgs(array($encoding))->getMock();
     $this->lame = new Lame(vfsStream::url('root/usr/bin/lame'), $settings);
 }
コード例 #25
0
ファイル: Config.Test.php プロジェクト: jwyuen/dotslash
 public function test_getEmailSesConfig_ReturnsCorrectConfig()
 {
     $sampleConfigDirectory = (include DOTSLASH_FIXTURES_PATH . 'exampleConfigDirectory.php');
     $expectedConfig = array('aws-access-key' => 'iamkey', 'aws-secret-key' => 'iamkeysecret', 'region' => 'murica-region-1', 'email-recipient' => '*****@*****.**');
     $configPath = 'root';
     $configRoot = vfsStream::setup($configPath);
     $root = vfsStream::create($sampleConfigDirectory, $configRoot);
     $url = vfsStream::url($configPath);
     $config = new Config($url);
     $actualConfig = $config->getEmailSesConfig();
     $this->assertEquals($expectedConfig, $actualConfig);
 }
コード例 #26
0
ファイル: DotLogger.Test.php プロジェクト: jwyuen/dotslash
 public function test_Logger_Works()
 {
     // Set up our mock file system
     $mockLogDirectory = array('logs');
     $rootPath = 'root';
     $configureRoot = vfsStream::setup($rootPath);
     $root = vfsStream::create($mockLogDirectory, $configureRoot);
     $logPath = vfsStream::url($rootPath);
     // Test our logger works
     $logger = new DotLogger('logger-test', $logPath);
     $this->assertTrue($logger->addInfo('adsf'));
 }
コード例 #27
0
ファイル: Parser.Test.php プロジェクト: jwyuen/configee-php
 public function test_getConfigurationGetsCorrectConfig()
 {
     $sampleConfigDirectory = (include __DIR__ . '/fixtures/exampleConfigDirectory.php');
     $expectedResult = array('general' => array(), 'production' => array('db' => array('host' => 'localhost', 'user' => 'someusername', 'password' => 'somepassword'), 'anotherfolder' => array('somefile' => array())), 'development' => array('db' => array('host' => 'localhost', 'user' => 'someusername', 'password' => 'somepassword')));
     $configPath = 'root';
     $configRoot = vfsStream::setup($configPath);
     $root = vfsStream::create($sampleConfigDirectory, $configRoot);
     $url = vfsStream::url($configPath);
     $parser = new Parser($url);
     $result = $parser->getConfiguration();
     $this->assertEquals($result, $expectedResult);
 }
コード例 #28
0
 /**
  * Checks if the loader accepts a file path as target.
  */
 public function testLoadClassFromFile()
 {
     $class = '<?php namespace Vendor\\Package; class Test extends \\Athletic\\AthleticEvent {}';
     $structure = array('src' => array('Package' => array('Test.php' => $class)));
     vfsStream::create($structure, $this->root);
     $path = vfsStream::url('root/src/Package/Test.php');
     $mockParser = m::mock('\\Athletic\\Discovery\\Parser')->shouldReceive('isAthleticEvent')->once()->andReturn(true)->getMock()->shouldReceive('getFQN')->once()->andReturn('Vendor\\Package\\Test')->getMock();
     $mockParserFactory = m::mock('\\Athletic\\Factories\\ParserFactory')->shouldReceive('create')->once()->with('vfs://root/src/Package/Test.php')->andReturn($mockParser)->getMock();
     $fileLoader = new RecursiveFileLoader($mockParserFactory, $path);
     $classes = $fileLoader->getClasses();
     $expectedClasses = array('Vendor\\Package\\Test');
     $this->assertEquals($expectedClasses, $classes);
 }
コード例 #29
0
 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);
 }
コード例 #30
0
ファイル: FSDiscovererTest.php プロジェクト: phpassert/core
 /**
  * @runInSeparateProcess
  * @preserveGlobalState disabled
  * @dataProvider testsFileStructureProvider
  */
 function testTestsFound(array $fileStructure, array $testObjects)
 {
     $fs = vfsStream::create($fileStructure, vfsStream::setup());
     $discoverer = new FSDiscoverer($fs->url());
     $tests = $discoverer->findTests();
     $this->assertEquals(array_map(function ($obj) {
         if (isset($obj['name'])) {
             return new $obj['class']($obj['name']);
         } else {
             return new $obj['class'](new $obj['instance']());
         }
     }, $testObjects), $tests);
 }