/**
  * @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());
 }
 /**
  * @test
  */
 public function shouldUpdateVersionInEmConf()
 {
     $service = new EmConfService($this->root->url(), 'extension_manager');
     $service->updateVersion('47.11.4711');
     $service->write();
     $this->assertRegExp('~\'version\' => \'47\\.11\\.4711\'~', $this->emConf->getContent());
 }
Beispiel #3
0
 /**
  * @test
  */
 public function load_class_metadata_loads()
 {
     $root = vfsStream::setup();
     $root->addChild($file = new vfsStreamFile('mapping.xml'));
     $loader = new TestLoader($file->url());
     $this->assertTrue($loader->loadClassMetadata($this->prophesize('Kcs\\Metadata\\ClassMetadata')->reveal()));
 }
Beispiel #4
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'));
 }
 public function testSetFile()
 {
     $sut = new JsonSchema();
     self::assertNull($sut->getFile());
     $sut->setFile($expected = $this->schema->url());
     self::assertEquals($expected, $sut->getFile());
 }
 /**
  * @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();
 }
 /**
  * @test
  */
 public function canWriteIntoLargeFile()
 {
     $fp = fopen($this->largeFile->url(), 'rb+');
     fseek($fp, 100 * 1024 * 1024, SEEK_SET);
     fwrite($fp, 'foobarbaz');
     fclose($fp);
     $this->largeFile->seek(100 * 1024 * 1024 - 3, SEEK_SET);
     $this->assertEquals('   foobarbaz   ', $this->largeFile->read(15));
 }
 /**
  * @test
  */
 public function shouldUpdateVersionNumber()
 {
     /** @var EmConfCommand $gitCommand */
     $application = new Application();
     $application->add(new EmConfCommand());
     $command = $application->find('emconf');
     $commandTester = new CommandTester($command);
     $commandTester->execute(array('command' => $command->getName(), 'path' => $this->root->url(), 'extension' => 'extension_manager', '--version-number' => '0.0.1'));
     $this->assertRegExp('~\'version\' => \'0\\.0\\.1\'~', $this->emConf->getContent());
 }
 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'));
 }
 /**
  * @test
  */
 public function createsHelloPhpRoute()
 {
     $routes = $this->routeLoader->load('.', 'legacy');
     $legacyRoute = $routes->get('basster.legacy.hello');
     $routePath = '/hello.php';
     self::assertNotNull($legacyRoute);
     self::assertEquals($routePath, $legacyRoute->getPath());
     self::assertEquals($this->legacyFile->url(), $legacyRoute->getDefault('legacyScript'));
     self::assertEquals($routePath, $legacyRoute->getDefault('requestPath'));
 }
 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);
 }
 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'));
 }
 protected function createBinDirectory(vfsStreamDirectory $rootDirectory)
 {
     $directory = new vfsStreamDirectory('bin');
     $rootDirectory->addChild($directory);
     $checkFile = new vfsStreamFile('check.sh', 0755);
     $checkFile->lastAccessed(mktime(23, 10, 23, 12, 14, 1977))->lastAttributeModified(mktime(23, 10, 23, 12, 14, 1977))->lastModified(mktime(23, 10, 23, 12, 14, 1977));
     $directory->addChild($checkFile);
     $runFile = new vfsStreamFile('run.sh');
     $runFile->chown(vfsStream::OWNER_USER_1)->chgrp(vfsStream::GROUP_USER_1)->withContent(LargeFileContent::withKilobytes(3));
     $directory->addChild($runFile);
 }
    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;
 }
 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");
 }
 /**
  * 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);
 }
 /**
  * @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');
 }
Beispiel #20
0
 /**
  * @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']);
 }
 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;
 }
 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')));
 }
Beispiel #23
0
 public function testWritingATransactionWillSaveItToXMLFileAndIncrementTheTransactionSequenceNumber()
 {
     $this->sut->writeJournal($this->journal);
     $txnId = $this->sut->setJournalName(new StringType('Foo Journal'))->writeTransaction($this->createTransaction('0000', '00001', 12.26));
     $this->assertEquals(new IntType(1), $txnId);
     $expectedFileName = $this->root->url() . '/foo-journal.xml';
     $this->assertFileExists($expectedFileName);
     $testDom = new \DOMDocument();
     $testDom->load($expectedFileName);
     $textXpath = new \DOMXPath($testDom);
     //file has transaction
     $txn = $textXpath->query("/journal/transactions/transaction[@id='1']");
     $this->assertEquals(1, $txn->length);
     //inc === 1
     $inc = $textXpath->query('/journal/definition')->item(0)->attributes->getNamedItem('inc')->nodeValue;
     $this->assertEquals(1, intval($inc));
 }
 /**
  * @param string   $filename
  * @param DateTime $modifiedTime
  *
  * @return vfsStreamFile
  */
 private function getMockModifiedFile($filename, $modifiedTime)
 {
     $file = new vfsStreamFile('foo.txt');
     $file->lastModified($modifiedTime->getTimestamp());
     $this->root->addChild($file);
     return $file;
 }
Beispiel #25
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)));
 }
 /**
  * visit a file and process it
  *
  * @param   vfsStreamFile  $file
  * @return  vfsStreamPrintVisitor
  */
 public function visitFile(vfsStreamFile $file)
 {
     $this->printContent($file->getName());
     return $this;
 }
 /**
  * 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');
 }
 /**
  * visit a file and process it
  *
  * @param   vfsStreamFile  $file
  * @return  vfsStreamStructureVisitor
  */
 public function visitFile(vfsStreamFile $file)
 {
     $this->current[$file->getName()] = $file->getContent();
     return $this;
 }
 /**
  * @test
  */
 public function unlockSiteRemovesLockFlagFile()
 {
     $this->lockManager->unlockSite();
     $this->assertFileNotExists($this->mockLockFlagFile->url());
 }