getRoot() публичный статический Метод

returns the root content
public static getRoot ( ) : org\bovigo\vfs\vfsStreamContainer
Результат org\bovigo\vfs\vfsStreamContainer
Пример #1
0
 private function createFile($filePath, $body = 'hello')
 {
     vfsStream::newFile($filePath)->at(vfsStreamWrapper::getRoot());
     $path = vfsStream::url('root/' . $filePath);
     file_put_contents($path, $body);
     return $path;
 }
 public function test_create_token_folder_if_it_does_not_exist()
 {
     $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('tokens'), 'Folder should not exists');
     $tokenizer = $this->instantiateClass('token_filename_retrieve.token', vfsStream::url('testDir/tokens'), $this->token_content, new Filesystem());
     $tokenizer->retrieve();
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('tokens'), 'Folder should now exists even if retrieve notes file does not');
 }
Пример #3
0
 public function testConstruct()
 {
     // test non existent file
     $nonExistentFilePath = "non/existent/file.php";
     try {
         new ConsoleRunner($nonExistentFilePath, $this->pidFactory, []);
         $this->fail("Should not be able to create a console runner without a console file that exists");
     } catch (RunnerException $e) {
         $this->assertContains($nonExistentFilePath, $e->getMessage());
     }
     // test non executable file
     $nonExecutableFilePath = "nonExecutableFile.php";
     $nonExecutableFile = vfsStream::newFile($nonExecutableFilePath, 00);
     vfsStreamWrapper::getRoot()->addChild($nonExecutableFile);
     $nonExecutableFilePath = $this->getPath($nonExecutableFilePath);
     try {
         new ConsoleRunner($nonExecutableFilePath, $this->pidFactory, []);
         $this->fail("Should not be able to create a console runner without a console file that is executable");
     } catch (RunnerException $e) {
         $this->assertContains($nonExecutableFilePath, $e->getMessage());
     }
     // test valid file
     $consolePath = "console.php";
     $nonExecutableFile = vfsStream::newFile($consolePath, 0444);
     vfsStreamWrapper::getRoot()->addChild($nonExecutableFile);
     $consolePath = $this->getPath($consolePath);
     $runner = new ConsoleRunner($consolePath, $this->pidFactory, []);
     $this->assertAttributeEquals($consolePath, "consolePath", $runner);
 }
Пример #4
0
 public function testFactoryCreateServiceWithName()
 {
     $this->init(array('logger' => array($this->key => array('path' => vfsStream::url('logs/default.log')))));
     $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('default.log'));
     $this->assertInstanceOf('Zend\\Log\\Logger', $this->factory->createServiceWithName($this->serviceLocator, $this->key, $this->key));
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('default.log'));
 }
Пример #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);
 }
 /**
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Writer\FilesystemWriter::write()
  * @covers Cocur\Bundle\BuildBundle\Writer\FilesystemWriter::getRealName()
  */
 public function writeShouldWriteIfFileIsInDirectory()
 {
     $root = vfsStreamWrapper::getRoot();
     $this->writer->write('/foo', 'Foobar');
     $this->assertTrue($root->hasChild('foo'));
     $this->assertTrue($root->getChild('foo')->hasChild('index.html'));
     $this->assertEquals('Foobar', $root->getChild('foo')->getChild('index.html')->getContent());
 }
Пример #7
0
 /**
  * @test
  */
 public function passwordShouldBeAddToRsaIfPasswordPassed()
 {
     vfsStream::newFile('id_rsa')->at(vfsStreamWrapper::getRoot());
     $authentication = new Rsa('root', vfsStream::url('root/id_rsa'), 'password');
     /** @var \Crypt_RSA $rsa */
     $rsa = $authentication->getAuthentication();
     $this->assertEquals('password', $rsa->password);
 }
Пример #8
0
 /**
  * Retrieves the virtual file system path
  *
  * @param string $path The path relative to the root folder
  *
  * @return string
  */
 protected function vfsPath($path = '')
 {
     $root = vfsStreamWrapper::getRoot()->getName();
     if (empty($path)) {
         return vfsStream::url($root);
     }
     return vfsStream::url($root . '/' . $path);
 }
 public function testSetLastUidCorrectly()
 {
     $this->initRoot();
     $file = vfsStream::url('home/lastui.json');
     $lastUidPersistFile = new LastUidPersistFile($file);
     $lastUidPersistFile->setLastUid(12);
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('lastui.json'), 'The file is not created');
     $this->assertTrue(file_get_contents($file) == json_encode(array('lastUid' => 12)), 'The file content is not correct');
 }
Пример #10
0
 public function testInitWithExistingIdxFile()
 {
     vfsStreamWrapper::getRoot()->addChild(new vfsStreamFile('idxfile.php'));
     $idx = $this->getMock('\\Idephix\\IdephixInterface');
     $idx->output = $this->getMock('Symfony\\Component\\Console\\Output\\OutputInterface');
     $idx->output->expects($this->exactly(1))->method('writeln')->with("<error>An idxfile.php already exists, generation skipped.</error>");
     $initIdxFile = new InitIdxFile('vfs://root');
     $initIdxFile->setIdephix($idx);
     $initIdxFile->initFile();
 }
Пример #11
0
 /**
  * @expectedException        Message\Cog\Config\Exception
  * @expectedExceptionMessage Config file `vfs://config/myconfig.yml` is not readable
  */
 public function testExceptionThrownWhenConfigFileNotReadable()
 {
     vfsStream::setup('config');
     vfsStream::newFile('myconfig.yml', 0333)->at(vfsStreamWrapper::getRoot());
     $env = new FauxEnvironment();
     $env->set('staging');
     $loader = new Loader(vfsStream::url('config'), $env);
     $registry = new NonLoadingRegistry($loader);
     $loader->load($registry);
 }
Пример #12
0
 /**
  * testPartial
  *
  * @since 2.3.0
  */
 public function testPartial()
 {
     /* setup */
     Stream::setup('root');
     $file = new StreamFile('partial.phtml');
     StreamWrapper::getRoot()->addChild($file);
     /* actual */
     $actual = Template::partial(Stream::url('root/partial.phtml'));
     /* compare */
     $this->assertTrue(is_string($actual));
 }
 function it_checks_whether_a_file_is_writable()
 {
     $root = vfsStreamWrapper::getRoot();
     vfsStream::newFile('writable.txt', 0666)->at($root);
     vfsStream::newFile('not_writable.txt', 0444)->at($root);
     $rootPath = vfsStream::url('root') . DIRECTORY_SEPARATOR;
     $file1 = $rootPath . 'writable.txt';
     $this->writable($file1)->shouldBe(true);
     $file2 = $rootPath . 'not_writable.txt';
     $this->writable($file2)->shouldBe(false);
 }
Пример #14
0
 public function setUp(DiInterface $di = NULL, Config $config = NULL)
 {
     vfsStream::setup('root');
     vfsStream::newFile('modules/module1/config/services.yml')->at(vfsStreamWrapper::getRoot());
     vfsStream::newFile('modules/module2/config/services.yml')->at(vfsStreamWrapper::getRoot());
     vfsStream::newFile('config/config.yml')->at(vfsStreamWrapper::getRoot());
     $this->module1 = vfsStream::url('root/modules/module1');
     $this->module2 = vfsStream::url('root/modules/module2');
     $this->configFile = vfsStream::url('root/config/config.yml');
     parent::setUp($di, $config);
 }
 /**
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Generator\FileGenerator::generate()
  */
 public function generateShouldReturnListOfParameters()
 {
     $file = vfsStream::newFile('parameters.txt')->at(vfsStreamWrapper::getRoot());
     $generator = new FileGenerator(['filename' => vfsStream::url('data/parameters.txt'), 'parameter' => 'var']);
     $file->setContent("param1\nparam2\nparam3\n");
     $parameters = $generator->generate();
     $this->assertCount(3, $parameters);
     $this->assertEquals('param1', $parameters[0]['var']);
     $this->assertEquals('param2', $parameters[1]['var']);
     $this->assertEquals('param3', $parameters[2]['var']);
 }
 public static function newFile($contents, $fileName = null, $root = null)
 {
     $root = is_null($root) ? 'root' : $root;
     $fileName = is_null($fileName) ? 'test.txt' : $fileName;
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory($root));
     $file = vfsStream::newFile($fileName);
     $file->setContent($contents);
     vfsStreamWrapper::getRoot()->addChild($file);
     $virtualPath = vfsStream::url($root . '/' . $fileName);
     return $virtualPath;
 }
Пример #17
0
 public function testFileDownload()
 {
     $controller = $this->getController();
     $download = $this->getControllerMethod($controller, 'fileDownload');
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('unitTest'));
     vfsStreamWrapper::getRoot()->addChild(new vfsStreamFile('unitText.txt'));
     /** @var Response $response */
     $response = $download->invoke($controller, vfsStream::url('unitTest/unitText.txt'));
     $this->assertTrue($response instanceof BinaryFileResponse);
     $this->assertEquals('attachment; filename="unitText.txt"', $response->headers->get('Content-Disposition'));
 }
 protected function makeJsonSelectHandler($filesPresent = false)
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory("testSaveDir"));
     if ($filesPresent) {
         $directory = new vfsStreamDirectory('Test');
         $directory->addChild(new vfsStreamFile('Test.json'));
         vfsStreamWrapper::getRoot()->addChild($directory);
     }
     $jsonSelectHandler = new JsonSelectHandler(vfsStream::url("testSaveDir"));
     return $jsonSelectHandler;
 }
    /**
     * @test
     */
    public function saveStoresFormDefinitionAsYaml()
    {
        $mockArrayFormDefinition = array('type' => 'TYPO3.Form:Form', 'identifier' => 'formFixture', 'label' => 'Form Fixture');
        $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('mockFormPersistenceIdentifier.yaml'));
        $this->yamlPersistenceManager->save('mockFormPersistenceIdentifier', $mockArrayFormDefinition);
        $expectedResult = 'type: \'TYPO3.Form:Form\'
identifier: formFixture
label: \'Form Fixture\'
';
        $actualResult = file_get_contents(vfsStream::url('someSavePath/mockFormPersistenceIdentifier.yaml'));
        $this->assertEquals($expectedResult, $actualResult);
    }
    public static function setUpBeforeClass()
    {
        self::$mtime = time();
        self::$fixtureString = '<' . '?php
			$EM_CONF[$_EXTKEY] = ' . var_export(self::$fixture, TRUE) . ';
		';
        $emConf = new vfsStreamFile('ext_emconf.php');
        $emConf->setContent(self::$fixtureString);
        vfsStreamWrapper::register();
        vfsStreamWrapper::setRoot(new vfsStreamDirectory('temp', 0777));
        vfsStreamWrapper::getRoot()->addChild($emConf);
    }
 /**
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Generator\YamlGenerator::generate()
  */
 public function generateShouldReturnListOfParametersThatMatch()
 {
     $file = vfsStream::newFile('parameters.yml')->at(vfsStreamWrapper::getRoot());
     $generator = new YamlGenerator(['filename' => vfsStream::url('data/parameters.yml'), 'parameters' => ['a']]);
     $file->setContent(Yaml::dump([['a' => 'param1a', 'b' => 'param1b'], ['a' => 'param2a', 'b' => 'param2b']]));
     $parameters = $generator->generate();
     $this->assertCount(2, $parameters);
     $this->assertCount(1, $parameters[0]);
     $this->assertCount(1, $parameters[1]);
     $this->assertEquals('param1a', $parameters[0]['a']);
     $this->assertEquals('param2a', $parameters[1]['a']);
 }
 public function testGetModuleConfig()
 {
     $moduleConfig = $this->fileCache->getModuleConfig('test', realpath(__DIR__ . '/../Resources/example-config.xml'));
     $this->assertNotEmpty($moduleConfig);
     $this->assertTrue($moduleConfig instanceof \Phruts\Config\ModuleConfig);
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('phruts-test.data'));
     $this->assertTrue(count($moduleConfig->findActionConfigs()) > 0);
     $moduleConfig2 = $this->fileCache->getModuleConfig('test', realpath(__DIR__ . '/../Resources/example-config.xml'));
     $this->assertEquals($moduleConfig, $moduleConfig2);
     touch(realpath(__DIR__ . '/../Resources/example-config.xml'), strtotime('+10 minutes'));
     $moduleConfig3 = $this->fileCache->getModuleConfig('test', realpath(__DIR__ . '/../Resources/example-config.xml'));
     $this->assertEquals($moduleConfig, $moduleConfig3);
 }
 protected function makeFormPopulator($filesPresent = false)
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory("testSaveDir"));
     if ($filesPresent) {
         $file = new vfsStreamFile('Test.json');
         $file->setContent("{\"just test json\" : \"just test json\"}");
         $directory = new vfsStreamDirectory('Test');
         $directory->addChild($file);
         vfsStreamWrapper::getRoot()->addChild($directory);
     }
     $formPopulator = new FormPopulator(vfsStream::url("testSaveDir"));
     return $formPopulator;
 }
Пример #24
0
 public function testSetDirectory()
 {
     vfsStream::setup('Fixtures');
     $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('foo'));
     $dir = vfsStream::url('Fixtures/foo');
     Cache::setDirectory($dir);
     $this->assertEquals($dir, Cache::getDirectory());
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('foo'));
     $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('bar'));
     $dir = vfsStream::url('Fixtures/bar');
     Cache::setDirectory($dir);
     $this->assertEquals($dir, Cache::getDirectory());
     $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('bar'));
 }
 protected function getSaveDirectory($filesPresent = false)
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory("testSaveDir"));
     if ($filesPresent) {
         $file = new vfsStreamFile('Test.php');
         $string = "<?php namespace Test;\n\t\t\t\t\t\t\tuse Doctrine\\ORM\\Mapping as ORM;\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t* @ORM\\Entity\n\t\t\t\t\t\t\t* @ORM\\Table(name=\"test\")\n\t\t\t\t\t\t\t*/\n\t\t\t\t\t\t\tclass Test {\n\t\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t\t* @ORM\\Id\n\t\t\t\t\t\t\t\t* @ORM\\GeneratedValue(strategy=\"AUTO\")\n\t\t\t\t\t\t\t\t* @ORM\\Column(type=\"string\", name=\"id\")\n\t\t\t\t\t\t\t\t*/\n\t\t\t\t\t\t\t\tprotected \$id;\n\t\t\t\t\t\t\t\tpublic function setId(\$id = null) {\n\t\t\t\t\t\t\t\t\t\$this->id = \$id;\n\t\t\t\t\t\t\t\t\treturn \$this;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tpublic function getId() {\n\t\t\t\t\t\t\t\t\treturn \$this->id;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}";
         $file->setContent($string);
         $directory = new vfsStreamDirectory('Test');
         $directory->addChild($file);
         vfsStreamWrapper::getRoot()->addChild($directory);
     }
     return vfsStream::url("testSaveDir");
 }
 /**
  * @test
  *
  * @covers Cocur\Bundle\BuildBundle\Generator\DirectoryGenerator::generate()
  */
 public function generateShouldReturnListOfParameters()
 {
     $root = vfsStreamWrapper::getRoot();
     $dir = new vfsStreamDirectory('data');
     $root->addChild($dir);
     $dir->addChild(vfsStream::newFile('param1.txt'));
     $dir->addChild(vfsStream::newFile('param2.txt'));
     $dir->addChild(vfsStream::newFile('param3.txt'));
     $generator = new DirectoryGenerator(['directory_name' => $dir->url(), 'parameter' => 'var']);
     $parameters = $generator->generate();
     $this->assertCount(3, $parameters);
     $this->assertEquals('param1', $parameters[0]['var']);
     $this->assertEquals('param2', $parameters[1]['var']);
     $this->assertEquals('param3', $parameters[2]['var']);
 }
Пример #27
0
 function testProxyDirectoryCreate()
 {
     //Make a directory you can write into
     vfsStream::newDirectory('tmp/write', 0775)->at(vfsStreamWrapper::getRoot());
     //Create a new arachnid instance with a proxy path inside the new directory
     $a = new Arachnid(array('transport' => 'curl', 'host' => 'localhost', 'port' => 7474, 'username' => 'neo4j', 'password' => 'password', 'proxy_dir' => vfsStream::url('tmp/write') . '/new', 'debug' => true));
     //Do a persist and reload (to generate a proxy)
     $u1 = new UserForUncreatableProxy();
     $u1->setFirstName('Lukas');
     $u1->setTestId($this->id);
     $a->persist($u1);
     $a->flush();
     $a->reload($u1);
     //Make sure the folder was created
     $this->assertFileExists(vfsStream::url('tmp/write') . '/new');
 }
Пример #28
0
    public function testScriptTagWithoutContentInIncludedFile()
    {
        vfsStream::setup('root');
        $template = <<<TEMPLATE
<fig:template xmlns:fig="http://www.figdice.org">
  <link href="/assets/style.css" rel="stylesheet" />
  <fig:include file="inner.html" />
</fig:template>
TEMPLATE;
        vfsStream::newFile('outer.html')->withContent($template)->at(vfsStreamWrapper::getRoot());
        $template = <<<TEMPLATE
<fig:template>
  <script src="/assets/require.js"></script>
</fig:template>
TEMPLATE;
        $innerVFile = vfsStream::newFile('inner.html');
        $innerVFile->withContent($template)->at(vfsStreamWrapper::getRoot());
        $filename = vfsStream::url('root/outer.html');
        $view = new View();
        $view->loadFile($filename);
        $output = $view->render();
        $expected = <<<EXPECTED
  <link href="/assets/style.css" rel="stylesheet" />
  <script src="/assets/require.js"></script>
EXPECTED;
        $this->assertEquals(trim($expected), trim($output));
        // Now test by inverting the script and link, so that the script is no longer
        // the last tag in the template (Bolek's test)
        $template = <<<TEMPLATE
<fig:template>
  <script src="/assets/require.js"></script>
  <link href="/assets/style.css" rel="stylesheet" />
</fig:template>
TEMPLATE;
        $innerVFile->setContent($template);
        $expected = <<<EXPECTED
  <link href="/assets/style.css" rel="stylesheet" />
  <script src="/assets/require.js"></script>
  <link href="/assets/style.css" rel="stylesheet" />
EXPECTED;
        $view = new View();
        $view->loadFile($filename);
        $output = $view->render();
        $this->assertEquals(trim($expected), trim($output));
    }
Пример #29
0
 public static function getVfsStreamDirectory($path)
 {
     if ($path instanceof vfsStreamContainer) {
         return $path;
     }
     $VfsRootDirectory = vfsStreamWrapper::getRoot();
     if (is_null($VfsRootDirectory)) {
         vfsStreamWrapper::register();
         $VfsDirectory = new vfsStreamDirectory($path);
         $VfsRootDirectory = new vfsStreamDirectory(uniqid('blade-'));
         $VfsRootDirectory->addChild($VfsDirectory);
         vfsStreamWrapper::setRoot($VfsRootDirectory);
     } else {
         $VfsDirectory = new vfsStreamDirectory($path);
         $VfsBladeDirectory = new vfsStreamDirectory(uniqid('blade-'));
         $VfsBladeDirectory->addChild($VfsDirectory);
         $VfsRootDirectory->addChild($VfsBladeDirectory);
     }
     return $VfsDirectory;
 }
 /**
  * @covers WindowsAzure\ServiceRuntime\Internal\FileInputChannel::getInputStream
  * @covers WindowsAzure\ServiceRuntime\Internal\FileInputChannel::closeInputStream
  */
 public function testGetInputStream()
 {
     $rootDirectory = 'root';
     $fileName = 'test.txt';
     $fileContent = 'somecontent';
     // Setup
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory($rootDirectory));
     $file = vfsStream::newFile($fileName);
     $file->setContent($fileContent);
     vfsStreamWrapper::getRoot()->addChild($file);
     // Test
     $fileInputChannel = new FileInputChannel();
     $inputStream = $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . $fileName));
     $inputChannelContents = stream_get_contents($inputStream);
     $this->assertEquals($fileContent, $inputChannelContents);
     $fileInputChannel->closeInputStream();
     // invalid file
     $this->setExpectedException(get_class(new ChannelNotAvailableException()));
     $fileInputChannel->getInputStream(vfsStream::url($rootDirectory . '/' . 'fakeinput'));
 }