setup() public static method

Instead of vfsStreamWrapper::register(); vfsStreamWrapper::setRoot(vfsStream::newDirectory('root')); you can simply do vfsStream::setup() which yields the same result. Additionally, the method returns the freshly created root directory which you can use to make further adjustments to it. 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:
root
\- 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.
See also: https://github.com/mikey179/vfsStream/issues/14
See also: https://github.com/mikey179/vfsStream/issues/20
Since: 0.7.0
public static setup ( string $rootDirName = 'root', integer $permissions = null, array $structure = [] ) : vfsStreamDirectory
$rootDirName string name of root directory
$permissions integer file permissions of root directory
$structure array directory structure to add under root directory
return vfsStreamDirectory
Example #1
0
 public function testGetTranslations_shouldReturnEmptyArray()
 {
     $root = vfsStream::setup('root');
     $root->addChild(new vfsStreamFile('language.php'));
     $obj = new Language_File(vfsStream::url('root/language.php'));
     $this->assertEquals(array(), $obj->getTranslations());
 }
Example #2
0
 /**
  * We ignore items that are not covered by the map.
  */
 public function testLoadUncovered()
 {
     vfsStream::setup('StaticMapTestLoadUncovered', null, ['a.php' => '<?php']);
     $object = new StaticMap(['A' => vfsStream::url('a.php'), 'B' => vfsStream::url('Covered.php')]);
     $object->load('StaticMapTestLoadUncoveredC_XYZ');
     $this->assertFalse(class_exists('StaticMapTestLoadUncoveredC_XYZ', false));
 }
 /**
  * @test
  */
 public function visitRecursiveDirectoryStructure()
 {
     $root = vfsStream::setup('root', null, array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world'), 'foo.txt' => ''));
     $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
     $this->assertSame($printVisitor, $printVisitor->visitDirectory($root));
     $this->assertEquals("- root\n  - test\n    - foo\n      - test.txt\n    - baz.txt\n  - foo.txt\n", file_get_contents('vfs://root/foo.txt'));
 }
 protected function setUp()
 {
     $this->fileSystem = vfsStream::setup();
     $file = vfsStream::newFile('template');
     $this->fileSystem->addChild($file);
     $this->filePath = $file->url();
 }
Example #5
0
 public function setUp(DiInterface $di = NULL, Config $config = NULL)
 {
     vfsStream::setup('root');
     vfsStream::newFile('file.php')->at(vfsStreamWrapper::getRoot());
     $this->file = vfsStream::url('root/file.php');
     parent::setUp($di, $config);
 }
Example #6
0
 /**
  * set up test environment
  */
 public function setUp()
 {
     $root = vfsStream::setup();
     $this->file = vfsStream::newFile('foo.txt')->withContent("bar\nbaz")->at($root);
     $this->underlyingStream = fopen($this->file->url(), 'rb+');
     $this->stream = new Stream($this->underlyingStream);
 }
Example #7
0
 /**
  * @expectedException \ErrorException
  * @covers \Asm\Ansible\Ansible::checkCommand
  * @covers \Asm\Ansible\Ansible::checkDir
  * @covers \Asm\Ansible\Ansible::__construct
  */
 public function testAnsibleCommandNotExecutableException()
 {
     $vfs = vfsStream::setup('/tmp');
     $ansiblePlaybook = vfsStream::newFile('ansible-playbook', 600)->at($vfs);
     $ansibleGalaxy = vfsStream::newFile('ansible-galaxy', 444)->at($vfs);
     $ansible = new Ansible($this->getProjectUri(), $ansiblePlaybook->url(), $ansibleGalaxy->url());
 }
Example #8
0
 /**
  * Setup the test
  */
 public function setUp()
 {
     vfsStream::setup('root', null, array('test' => 'testing'));
     $this->file = vfsStream::url('root/test');
     $this->properties = $this->getMock('\\Pants\\Property\\Properties');
     $this->task = new Copy($this->properties);
 }
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $this->dir = vfsStream::setup();
     $dir = $this->dir;
     $tempDir = vfsStream::url($dir->getName()) . '/';
     $this->media = $this->getMock('\\Oryzone\\MediaStorage\\Model\\MediaInterface');
     $this->media->expects($this->any())->method('getContext')->will($this->returnValue('default'));
     $this->media->expects($this->any())->method('getName')->will($this->returnValue('sample'));
     $this->media->expects($this->any())->method('getContent')->will($this->returnValue('http://vimeo.com/56974716'));
     $this->media->expects($this->any())->method('getMetaValue')->will($this->returnValueMap(array(array('id', null, '56974716'))));
     $this->variant = $this->getMock('\\Oryzone\\MediaStorage\\Variant\\VariantInterface');
     $this->variant->expects($this->any())->method('getName')->will($this->returnValue('default'));
     $this->variant->expects($this->any())->method('getOptions')->will($this->returnValue(array('width' => 50, 'height' => 30, 'resize' => 'stretch')));
     $this->variant->expects($this->any())->method('getMetaValue')->will($this->returnValueMap(array(array('width', null, 50), array('height', null, 30))));
     $image = $this->getMock('\\Imagine\\Image\\ImageInterface');
     $image->expects($this->any())->method('save')->will($this->returnCallback(function ($destFile) use($dir) {
         $temp = vfsStream::newFile(basename($destFile));
         $dir->addChild($temp);
         return true;
     }));
     $imagine = $this->getMock('\\Imagine\\Image\\ImagineInterface');
     $imagine->expects($this->any())->method('open')->will($this->returnValue($image));
     $downloader = $this->getMock('\\Oryzone\\MediaStorage\\Downloader\\DownloaderInterface');
     $downloader->expects($this->any())->method('download')->will($this->returnCallback(function ($url, $destination) use($dir) {
         $temp = vfsStream::newFile(basename($destination));
         $temp->setContent(file_get_contents(__DIR__ . '/../fixtures/images/sample.jpg'));
         $dir->addChild($temp);
         return true;
     }));
     $videoService = $this->getMock('\\Oryzone\\MediaStorage\\Integration\\Video\\VideoServiceInterface');
     $this->provider = new VimeoProvider($tempDir, $imagine, $videoService, $downloader);
 }
 /**
  * Sets up the test suite
  *
  * @return void
  */
 public function setUp()
 {
     $this->translator = m::mock('phpDocumentor\\Translator\\Translator');
     $this->checkStyle = new CheckStyle();
     $this->checkStyle->setTranslator($this->translator);
     $this->fs = vfsStream::setup('CheckStyleTest');
 }
 public function setUp()
 {
     $this->pubkeyName = 'tmp/public.key';
     $this->root = vfsStream::setup('tmp');
     $this->pubkeyStream = vfsStream::url($this->pubkeyName);
     $this->storage = new EncryptedFilesystemStorage('satoshi');
 }
 /**
  */
 public function setUp()
 {
     ComposerUtility::flushCaches();
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder(\Neos\Flow\Package\PackageManager::class)->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), true);
 }
Example #13
0
 public function setUp()
 {
     vfsStreamWrapper::register();
     $root = vfsStream::setup('logs');
     $mockFile = vfsStream::newFile('logging_helper.log')->at($root);
     $root->addChild($mockFile);
 }
Example #14
0
 public function setUp()
 {
     $this->stream = vfsStream::setup('root', 0777, self::$structure);
     Application::register('FileSystem', \Core\FileSystem\FileSystem::class);
     Application::register('Cache', \Core\Cache\FileCache::class)->setArguments(['FileSystem', vfsStream::url('root/cache')]);
     parent::setUp();
 }
 public function setUp()
 {
     $this->projectRoot = vfsStream::setup('project');
     $this->discovery = new ConfigDiscovery();
     $this->allTypes = new Collection([InjectorInterface::TYPE_CONFIG_PROVIDER, InjectorInterface::TYPE_COMPONENT, InjectorInterface::TYPE_MODULE]);
     $this->injectorTypes = [Injector\ApplicationConfigInjector::class, Injector\ConfigInjectorChain::class, Injector\ExpressiveConfigInjector::class, Injector\ModulesConfigInjector::class];
 }
 protected function setUpVfsStream()
 {
     if (!class_exists('org\\bovigo\\vfs\\vfsStream')) {
         $this->markTestSkipped('File backend tests are not available with this phpunit version.');
     }
     vfsStream::setup('LogRoot');
 }
 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);
 }
 public function setUp()
 {
     $this->setKernel(new \AppKernel('test', true));
     $this->getKernel()->boot();
     $structure = array('user' => array('logs' => array('access.log' => $this->getContentForAccessLog())));
     $this->homeDir = vfsStream::setup('home', 0777, $structure);
 }
Example #19
0
 public function setUp()
 {
     $this->service = new \Nbt\Service(new \Nbt\DataHandler());
     $this->vRoot = vfsStream::setup();
     $this->vFile = new vfsStreamFile('test.nbt');
     $this->vRoot->addChild($this->vFile);
 }
 /**
  */
 public function setUp()
 {
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder('TYPO3\\Flow\\Package\\PackageManager')->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), TRUE);
     $this->packageFactory = new PackageFactory($this->mockPackageManager);
 }
 public function setUp()
 {
     parent::setUp();
     $this->serviceManager = new ServiceManager();
     $this->pluginManager = new PluginManager();
     $this->root = vfsStream::setup('exampleDir', 0777);
 }
Example #22
0
 function let(ParserInterface $parser, FileChecksumInterface $fileChecksum)
 {
     $this->parser = $parser;
     $this->fileChecksum = $fileChecksum;
     $this->vfs = vfsStream::setup('root', null, ['dummy_file1.txt' => 'some_file_content1']);
     $this->beConstructedWith($parser, $this->vfs->url() . '/dummy_file1.txt', $this->fileChecksum);
 }
Example #23
0
    /**
     * {@inheritdoc}
     */
    public function testLoad()
    {
        $xml = <<<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<mediatypes>
    <mediatype name="mp4" category="video">
        <mimetypes>
            <mimetype>video/mp4</mimetype>
        </mimetypes>
    </mediatype>
    <mediatype name="jpg" category="image">
        <mimetypes>
            <mimetype>image/jpg</mimetype>
            <mimetype>image/jpeg</mimetype>
        </mimetypes>
    </mediatype>
</mediatypes>
EOF;
        vfsStream::setup('root', null, ['types.xml' => $xml]);
        $mediatypes = $this->loader->load(vfsStream::url('root/types.xml'));
        $this->assertCount(2, $mediatypes);
        $this->assertTrue($mediatypes->has('video:mp4'));
        $this->assertSame('mp4', $mediatypes->get('video:mp4')->getName());
        $this->assertSame('video', $mediatypes->get('video:mp4')->getCategory());
        $this->assertCount(1, $mediatypes->get('video:mp4')->getMimetypes());
        $this->assertSame(['video/mp4'], $mediatypes->get('video:mp4')->getMimetypes());
        $this->assertTrue($mediatypes->has('image:jpg'));
        $this->assertSame('jpg', $mediatypes->get('image:jpg')->getName());
        $this->assertSame('image', $mediatypes->get('image:jpg')->getCategory());
        $this->assertCount(2, $mediatypes->get('image:jpg')->getMimetypes());
        $this->assertSame(['image/jpg', 'image/jpeg'], $mediatypes->get('image:jpg')->getMimetypes());
    }
Example #24
0
 /**
  * Try to load a class that is outside the namespace.
  */
 public function testLoadOutside()
 {
     vfsStream::setup('root', null, ['NS' => ['A' => ['B.php' => '<?php class BPSRLoadExists_XYZ {}', 'C.php' => '<?php']]]);
     $object = new PSR0Namespace(vfsStream::url('root'), 'NS');
     $object->load('NS\\A\\D');
     $this->assertFalse(class_exists('NS\\A\\D', false));
 }
Example #25
0
 /**
  * Provides Mutex factories.
  *
  * @return callable[][] The mutex factories.
  */
 public function provideMutexFactories()
 {
     $cases = ["NoMutex" => [function () {
         return new NoMutex();
     }], "TransactionalMutex" => [function () {
         $pdo = new \PDO("sqlite::memory:");
         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         return new TransactionalMutex($pdo);
     }], "FlockMutex" => [function () {
         vfsStream::setup("test");
         return new FlockMutex(fopen(vfsStream::url("test/lock"), "w"));
     }], "SemaphoreMutex" => [function () {
         return new SemaphoreMutex(sem_get(ftok(__FILE__, "a")));
     }], "SpinlockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(SpinlockMutex::class, ["test"]);
         $mock->expects($this->any())->method("acquire")->willReturn(true);
         $mock->expects($this->any())->method("release")->willReturn(true);
         return $mock;
     }], "LockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(LockMutex::class);
         $mock->expects($this->any())->method("lock")->willReturn(true);
         $mock->expects($this->any())->method("unlock")->willReturn(true);
         return $mock;
     }]];
     if (getenv("MEMCACHE_HOST")) {
         $cases["MemcacheMutex"] = [function () {
             $memcache = new Memcache();
             $memcache->connect(getenv("MEMCACHE_HOST"));
             return new MemcacheMutex("test", $memcache);
         }];
         $cases["MemcachedMutex"] = [function () {
             $memcache = new Memcached();
             $memcache->addServer(getenv("MEMCACHE_HOST"), 11211);
             return new MemcachedMutex("test", $memcache);
         }];
     }
     if (getenv("REDIS_URIS")) {
         $uris = explode(",", getenv("REDIS_URIS"));
         $cases["PredisMutex"] = [function () use($uris) {
             $clients = array_map(function ($uri) {
                 return new Client($uri);
             }, $uris);
             return new PredisMutex($clients, "test");
         }];
         $cases["PHPRedisMutex"] = [function () use($uris) {
             $apis = array_map(function ($uri) {
                 $redis = new Redis();
                 $uri = parse_url($uri);
                 if (!empty($uri["port"])) {
                     $redis->connect($uri["host"], $uri["port"]);
                 } else {
                     $redis->connect($uri["host"]);
                 }
                 return $redis;
             }, $uris);
             return new PHPRedisMutex($apis, "test");
         }];
     }
     return $cases;
 }
 /**
  */
 public function setUp()
 {
     vfsStream::setup('testDirectory');
     $this->cache = $this->getMockBuilder(\Neos\Cache\Frontend\StringFrontend::class)->disableOriginalConstructor()->getMock();
     $this->strategy = new \Neos\Flow\Monitor\ChangeDetectionStrategy\ModificationTimeStrategy();
     $this->strategy->injectCache($this->cache);
 }
Example #27
0
 public function testLoadInValidFileType()
 {
     $this->setExpectedException('InvalidArgumentException');
     vfsStream::setup('webroot', null, array('img' => array('flower.foo' => 'foo')));
     $image = new Image();
     $image->load(vfsStream::url('webroot/img/flower.foo'));
 }
 /**
  * Creates the mocked filesystem used in the tests
  */
 public function setUp()
 {
     vfsStream::setup('Foo');
     $this->mockEnvironment = $this->getMock('TYPO3\\Flow\\Utility\\Environment', array(), array(), '', FALSE);
     $this->mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $this->mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(1024));
 }
 function it_creates_internal_io_factory_with_vfs_stream()
 {
     $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.vfs')->willReturn(vfsStream::setup('custom_root_dir'));
     $factory = $this->ioFactory();
     $factory->shouldImplement(\Closure::class);
     $factory($this->serviceContainer)->shouldImplement(Io::class);
 }
 /**
  * Sets up this test case
  *
  */
 protected function setUp()
 {
     vfsStream::setup('Test');
     $mockBootstrap = $this->getMock('TYPO3\\Flow\\Core\\Bootstrap', array(), array(), '', FALSE);
     $mockBootstrap->expects($this->any())->method('getSignalSlotDispatcher')->will($this->returnValue($this->getMock('TYPO3\\Flow\\SignalSlot\\Dispatcher')));
     $mockObjectManager = $this->getMock('TYPO3\\Flow\\Object\\ObjectManagerInterface');
     $mockBootstrap->expects($this->any())->method('getObjectManager')->will($this->returnValue($mockObjectManager));
     $mockReflectionService = $this->getMock('TYPO3\\Flow\\Reflection\\ReflectionService');
     $mockReflectionService->expects($this->any())->method('getClassNameByObject')->will($this->returnCallback(function ($object) {
         if ($object instanceof \Doctrine\ORM\Proxy\Proxy) {
             return get_parent_class($object);
         }
         return get_class($object);
     }));
     $mockObjectManager->expects($this->any())->method('get')->with('TYPO3\\Flow\\Reflection\\ReflectionService')->will($this->returnValue($mockReflectionService));
     $this->packageManager = new \TYPO3\Flow\Package\PackageManager();
     mkdir('vfs://Test/Packages/Application', 0700, TRUE);
     mkdir('vfs://Test/Configuration');
     $mockClassLoader = $this->getMock('TYPO3\\Flow\\Core\\ClassLoader');
     $composerNameToPackageKeyMap = array('typo3/flow' => 'TYPO3.Flow');
     $this->packageManager->injectClassLoader($mockClassLoader);
     $this->inject($this->packageManager, 'composerNameToPackageKeyMap', $composerNameToPackageKeyMap);
     $this->inject($this->packageManager, 'packagesBasePath', 'vfs://Test/Packages/');
     $this->inject($this->packageManager, 'packageStatesPathAndFilename', 'vfs://Test/Configuration/PackageStates.php');
     $this->packageManager->initialize($mockBootstrap);
 }