예제 #1
0
 /**
  * @throws \WPluginCore003\Diagnostics\Exception
  * @throws vfs\vfsStreamException
  * @static
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since  0.0.2
  */
 public static function setUpBeforeClass()
 {
     global $WpPluginCore;
     self::$WpPluginCore = $WpPluginCore;
     vfs\vfsStreamWrapper::register();
     self::$rootDir = new vfs\vfsStreamDirectory('rootDir');
     vfs\vfsStreamWrapper::setRoot(self::$rootDir);
     self::$templateBaseName = uniqid();
     self::$templateName = self::$templateBaseName . '.php';
     self::$misTemplateBaseName = uniqid('missing');
     self::$misTemplateName = self::$misTemplateBaseName . '.php';
     self::$templateFile = new vfs\vfsStreamFile(self::$templateName);
     self::$templateFile->setContent('<?php if(isset($var)) echo $var; else echo 1;');
     self::$rootDir->addChild(self::$templateFile);
     self::$templateObj = self::$WpPluginCore->getFactory()->createOrGet('Templates\\Template');
 }
예제 #2
0
 /**
  * @param string $path
  * @return \SplFileInfo
  */
 public function createFile($path, $content = null)
 {
     $file = new vfsStreamFile(basename($path));
     $file->setContent($content);
     $this->createPath(dirname($path))->addChild($file);
     return new \SplFileInfo($file->url());
 }
예제 #3
0
 /**
  * @test
  *
  * @covers Cocur\NQM\QueryLoader\FilesystemQueryLoader::getQuery()
  * @covers Cocur\NQM\QueryLoader\FilesystemQueryLoader::getQueryFilename()
  */
 public function getQueryShouldReturnQuery()
 {
     $file = new vfsStreamFile('foobar.sql');
     $file->setContent('SELECT * FROM table;');
     $this->rootDir->addChild($file);
     $this->assertEquals('SELECT * FROM table;', $this->loader->getQuery('foobar'));
 }
예제 #4
0
 /**
  * @test
  */
 public function testReadFromFile()
 {
     $vfsRoot = vfsStream::setup('root');
     $testFile = new vfsStreamFile('test');
     $testFile->setContent($this->getTestFileContent());
     $vfsRoot->addChild($testFile);
     $this->assertEquals($this->getExpectedResultArray(), $this->fixture->readFromFile($testFile->url()));
 }
 /**
  * Tests readinging too little in getMicrotime().
  *
  * @expectedException bandwidthThrottle\tokenBucket\storage\StorageException
  */
 public function testGetMicrotimeReadsToLittle()
 {
     $data = new vfsStreamFile("data");
     $data->setContent("1234567");
     vfsStream::setup('test')->addChild($data);
     $storage = new FileStorage(vfsStream::url("test/data"));
     $storage->getMicrotime();
 }
예제 #6
0
 public function testReadExpiredCached()
 {
     $root = vfsStream::setup('root');
     $fc = new FileCacheBackend(vfsStream::url('root'));
     $file = new vfsStreamFile('test');
     $file->setContent(pack("N", time() - 10) . 'test');
     $root->addChild($file);
     $this->assertEquals(null, $fc->read('test', null));
     $this->assertFalse($root->hasChild('test'));
 }
예제 #7
0
 protected function _setUpVfs()
 {
     $oneUimap = new vfsStreamFile('one.yml');
     $oneUimap->setContent($this->_oneUimapFileContent);
     $twoUimap = new vfsStreamFile('two.yml');
     $twoUimap->setContent($this->_twoUimapFileContent);
     $vfs = vfsStream::setup('uimaps');
     $vfs->addChild($oneUimap);
     $vfs->addChild($twoUimap);
 }
예제 #8
0
 public function testRead()
 {
     $root = vfsStream::setup('root');
     $storage = new FileServiceStorage(vfsStream::url('root'));
     $this->assertNull($storage->read('test'));
     $file = new vfsStreamFile('test');
     $file->setContent(serialize('123'));
     $root->addChild($file);
     $this->assertEquals('123', $storage->read('test'));
 }
    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);
    }
 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;
 }
예제 #11
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     parent::setUp();
     $directoryName = 'test';
     $filename = 'test.txt';
     $this->fileContent = 'test' . PHP_EOL . 'test' . PHP_EOL . 'test' . PHP_EOL . 'test';
     vfsStreamWrapper::register();
     $directory = new vfsStreamDirectory($directoryName);
     $file = new vfsStreamFile($filename);
     $file->setContent($this->fileContent);
     $directory->addChild($file);
     vfsStreamWrapper::setRoot($directory);
     $this->filePath = vfsStream::url($directoryName . DIRECTORY_SEPARATOR . $filename);
 }
 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");
 }
예제 #13
0
파일: PliTest.php 프로젝트: cocur/pli
 /**
  * @test
  * @covers Cocur\Pli\Pli::loadConfiguration()
  * @covers Cocur\Pli\Pli::getConfigFilename()
  */
 public function loadConfigurationShouldLoadConfiguration()
 {
     $rootNode = m::mock('Symfony\\Component\\Config\\Definition\\NodeInterface');
     $rootNode->shouldReceive('normalize')->once();
     $rootNode->shouldReceive('merge')->once();
     $rootNode->shouldReceive('finalize')->once()->andReturn(['foo' => 'bar']);
     $treeBuilder = m::mock('Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder');
     $treeBuilder->shouldReceive('buildTree')->once()->andReturn($rootNode);
     /** @var \Symfony\Component\Config\Definition\ConfigurationInterface|\Mockery\MockInterface $configuration */
     $configuration = m::mock('Symfony\\Component\\Config\\Definition\\ConfigurationInterface');
     $configuration->shouldReceive('getConfigTreeBuilder')->once()->andReturn($treeBuilder);
     $configFile = new vfsStreamFile('config.yml');
     $configFile->setContent('foo: bar');
     $this->configDir->addChild($configFile);
     $config = $this->pli->loadConfiguration($configuration, ['config.yml']);
     $this->assertEquals('bar', $config['foo']);
 }
예제 #14
0
 protected function _createContextWithDriver(DriverInterface $driver)
 {
     $uimapYaml = new vfsStreamFile('page.yml');
     $uimapYaml->setContent($this->_uimapYamlContent);
     $vfs = vfsStream::setup('vfs');
     $vfs->addChild($uimapYaml);
     $tafPageSource = new TafPageSource(vfsStream::url('vfs/page.yml'));
     $uimapSelector = new UimapSelector($tafPageSource);
     $selectorsHandler = new SelectorsHandler(array('uimap' => $uimapSelector));
     $sessionName = 'mocked';
     $mink = new Mink(array($sessionName => new Session($driver, $selectorsHandler)));
     $mink->setDefaultSessionName($sessionName);
     $context = $this->getObjectForTrait('Irs\\BehatUimapExtension\\Context\\UimapContext');
     $context->setMink($mink);
     $context->setPageSource($tafPageSource);
     $context->loadPage('category_page_before_reindex');
     return $context;
 }
예제 #15
0
 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')));
 }
예제 #16
0
 /**
  * Constructor
  */
 public function setUp()
 {
     $this->jsonFile = new vfsStreamFile('test.json');
     $this->jsonFile->setContent('{"foo": "bar"}');
     vfsStream::setup()->addChild($this->jsonFile);
 }
 /**
  * @test
  * it should replace old with new in output
  */
 public function it_should_replace_old_with_new_in_output()
 {
     $root = vfsStream::setup('source');
     $file = new vfsStreamFile('dump.sql');
     $file->setContent('foo baz bar foo baz bar');
     $root->addChild($file);
     $application = new Application();
     $application->add(new SearchReplace());
     $command = $application->find('search-replace');
     $commandTester = new CommandTester($command);
     $outputFile = $root->url() . '/out.sql';
     $commandTester->execute(['command' => $command->getName(), 'old' => 'foo', 'new' => 'replacement', 'file' => $root->url() . '/dump.sql', 'output' => $outputFile]);
     $this->assertStringEqualsFile($outputFile, 'replacement baz bar replacement baz bar');
 }
예제 #18
0
    /**
     * @test
     * it should allow setting var values
     */
    public function it_should_allow_setting_var_values()
    {
        $dir = vfsStream::setup();
        $configFile = new vfsStreamFile('conf.yaml');
        $configFileContent = <<<YAML
foo:
    var:
        name: one
        value: 23
    message: One is \$one
YAML;
        $configFile->setContent($configFileContent);
        $dir->addChild($configFile);
        $application = new Application();
        $application->add(new Setup());
        $command = $application->find('setup');
        $commandTester = new CommandTester($command);
        $helper = $command->getHelper('question');
        $helper->setInputStream($this->getInputStream("yes\n"));
        $commandTester->execute(['command' => $command->getName(), 'config' => $dir->url() . '/conf.yaml']);
        $display = $commandTester->getDisplay();
        $this->assertContains('One is 23', $display);
    }
예제 #19
0
 public function testCollectString_shouldNotConsiderEmptyCallsToTra()
 {
     $this->obj->addFileType(new Language_FileType_Php());
     $fileName = 'file1.php';
     $root = vfsStream::setup('root');
     $file = new vfsStreamFile($fileName);
     $file->setContent("'sub' => array(\n\t\t\t       'required' => false,\n\t\t\t       'default' => 'n',\n\t\t\t       'filter' => 'alpha',\n\t\t\t       'options' => array(\n\t\t\t           array('text' => tra(''), 'value' => ''),\n\t\t\t           array('text' => tra('Yes'), 'value' => 'y'),\n\t\t\t           array('text' => tra('No'), 'value' => 'n')\n\t\t\t       ),\n\t\t\t   ),");
     $root->addChild($file);
     $expectedResult = array('Yes', 'No');
     $this->assertEquals($expectedResult, $this->obj->collectStrings(vfsStream::url('root/' . $fileName)));
 }
예제 #20
0
 /**
  * @param string $content
  * @param int    $mode
  */
 protected function given_dump_file($content, $mode = 0777)
 {
     $file = new vfsStreamFile(self::DUMP_FILE, $mode);
     $file->setContent($content);
     $this->tmp_dir->addChild($file);
 }
 public function testWriteComposerFileReturnsWithoutWritingFileIfFileDoesNotContainVersion()
 {
     $versioner = new Versioner();
     $method = new \ReflectionMethod($versioner, 'writeComposerFile');
     $method->setAccessible(TRUE);
     $fixture = self::$fixture;
     unset($fixture['version']);
     $noVersionFile = Versioner::FILENAME_COMPOSER . '.noversion.json';
     $newComposerFile = new vfsStreamFile($noVersionFile);
     $newComposerFile->setContent(json_encode($fixture, JSON_UNESCAPED_SLASHES));
     vfsStreamWrapper::getRoot()->addChild($newComposerFile);
     $vfsUrl = vfsStream::url('temp/' . $noVersionFile);
     $result = $method->invokeArgs($versioner, array($vfsUrl, '1.2.3'));
     $this->assertTrue($result);
     $this->assertNotContains('1.2.3', file_get_contents($vfsUrl));
 }