protected function setUp() { $file = vfsStream::newFile('template'); $this->fileSystem = vfsStream::setup(); $this->fileSystem->addChild($file); $this->filePath = $file->url(); }
protected function setUp() { $this->basePath = vfsStream::setup(); $this->basePath->addChild(vfsStream::newDirectory('project')); $this->basePath->addChild(vfsStream::newDirectory('hooks')); $this->basePath->addChild(vfsStream::newDirectory('.git/hooks')); }
/** * @expectedException \EBT\ConfigLoader\Exception\InvalidArgumentException * @expectedExceptionMessage not readable */ public function testLoadFileNotReadable() { $this->root->addChild(vfsStream::newFile('file1')); // make sure is not readable $this->root->getChild('file1')->chown('testuser')->chgrp('testuser')->chmod(0750); (new JsonFileLoader())->load(vfsStream::url('test/file1')); }
/** */ public function testFustyRequest_ValidateUpload() { //// Setup test $firstChunk = vfsStream::newFile('temp_file'); $firstChunk->setContent('1234567890'); $this->vfs->addChild($firstChunk); $fileInfo = new \ArrayObject(array('size' => 10, 'error' => UPLOAD_ERR_OK, 'tmp_name' => $firstChunk->url())); $request = new \ArrayObject(array('flowIdentifier' => '13632-prettifyjs', 'flowFilename' => 'prettify.js', 'flowRelativePath' => 'home/prettify.js')); $fustyRequest = new FustyRequest($request, $fileInfo); $config = new Config(); $config->setTempDir($this->vfs->url()); /** @var File $file */ $file = $this->getMock('Flow\\File', array('_move_uploaded_file'), array($config, $fustyRequest)); /** @noinspection PhpUndefinedMethodInspection */ $file->expects($this->once())->method('_move_uploaded_file')->will($this->returnCallback(function ($filename, $destination) { return rename($filename, $destination); })); //// Actual test $this->assertTrue($file->validateChunk()); $this->assertFalse($file->validateFile()); $this->assertTrue($file->saveChunk()); $this->assertTrue($file->validateFile()); $path = $this->vfs->url() . DIRECTORY_SEPARATOR . 'new'; $this->assertTrue($file->save($path)); $this->assertEquals(10, filesize($path)); }
/** * {@inheritDoc} */ protected function setUp() { $this->root = vfsStream::setup(); $this->root->addChild(new vfsStreamFile('1.png')); $this->root->addChild(new vfsStreamFile('2.jpg')); $this->root->addChild(new vfsStreamFile('3.jpeg')); }
/** * @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')); }
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { $this->provider = new FileProvider(); $this->dir = vfsStream::setup('root'); $file = vfsStream::newFile('test'); $file->write('some content'); $this->dir->addChild($file); }
public function testIsFile() { $this->root->addChild(new vfsStreamDirectory('assets')); $dir = $this->root->getChild('assets'); $file = vfsStream::newFile('foo.txt')->withContent('foo')->at($this->root); $this->assertFalse($this->trait->isFile($dir->url())); $this->assertTrue($this->trait->isFile($file->url())); }
public function testForReadingWithOptionalKeyParameterConfigFile() { $configFile = vfsStream::newFile('config.inc.php'); $configFile->setContent('<?php return ["primary-key"=>["test-key"=>"test-value"]];'); $this->root->addChild($configFile); $configFileReading = new ConfigFileReader($this->root->getChild('config.inc.php')->url()); $this->assertEquals(['test-key' => 'test-value'], $configFileReading->getConfiguration('primary-key')); }
/** * @covers ::updateAddressFormats */ public function testUpdateAddressFormatsRemovesLegacyFiles() { $this->root->addChild(new vfsStreamFile('legacy.json')); $httpClient = new HttpClient(); $httpClient->setAdapter(new HttpTestAdapter()); $maintenanceService = new MaintenanceService($this->options, $httpClient); $maintenanceService->updateAddressFormats(); $this->assertFalse($this->root->hasChild('legacy.json')); }
public function testShouldBeAbleToCopyFile() { $this->root->addChild(vfsStream::newFile('testfile1copy')->setContent('TestContent')); $copy = new DefaultCopy($this->root->url() . '/testfile1', $this->root->url() . '/testfile1copy'); $copy->execute(); /** @var vfsStreamFile $copiedFile */ $copiedFile = $this->root->getChild('testfile1copy'); $this->assertEquals('testfile1copy', $copiedFile->getName()); $this->assertEquals('TestContent', $copiedFile->getContent()); }
public function testValidateContent() { $textFile = vfsStream::newFile('foo.txt'); $textFile->setContent('foo'); $this->dir->addChild($textFile); $this->assertFalse($this->provider->validateContent(NULL)); $this->assertFalse($this->provider->validateContent(1234)); $this->assertFalse($this->provider->validateContent(vfsStream::url('root/foo.txt'))); $imagePath = vfsStream::url('root/sample.jpg'); $this->assertTrue($this->provider->validateContent($imagePath)); $this->assertTrue($this->provider->validateContent(new \SplFileInfo($imagePath))); }
public function testModuleInit() { $this->vfsRoot->addChild($this->createFile('file1')); $this->vfsRoot->addChild($this->createFile('file1')); $this->vfsRoot->addChild(vfsStream::newDirectory('dir1')); AspectMock::double(\Codeception\Configuration::class, ['outputDir' => vfsStream::url('outputDir')]); // Cleansman needs no configuration atm $event = m::mock(\Codeception\Event\SuiteEvent::class); $sut = new \Codeception\Extension\Cleansman([], ['silent' => false]); // Actual cleanup happens here $sut->moduleInit($event); $this->assertFalse($this->vfsRoot->hasChild('file1')); $this->assertFalse($this->vfsRoot->hasChild('file2')); $this->assertFalse($this->vfsRoot->hasChild('dir1')); }
protected function createVendorDirectory(vfsStreamDirectory $rootDirectory) { $directory = new vfsStreamDirectory('vendor'); $rootDirectory->addChild($directory); $directory->addChild(new vfsStreamFile('autoload.php')); $subDirectory = new vfsStreamDirectory('composer'); $directory->addChild($subDirectory); $subDirectory->addChild(new vfsStreamFile('autoload_classmap.php')); $subDirectory->addChild(new vfsStreamFile('autoload_namespaces.php')); $subDirectory->addChild(new vfsStreamFile('autoload_psr4.php')); $subDirectory->addChild(new vfsStreamFile('autoload_real.php')); $subDirectory->addChild(new vfsStreamFile('ClassLoader.php')); $subDirectory->addChild(new vfsStreamFile('installed_paths.php')); $subDirectory->addChild(new vfsStreamFile('installed.json')); $subDirectory = new vfsStreamDirectory('psr'); $directory->addChild($subDirectory); $secondLevelSubDirectory = new vfsStreamDirectory('log'); $subDirectory->addChild($secondLevelSubDirectory); $secondLevelSubDirectory->addChild(new vfsStreamFile('.gitignore')); $secondLevelSubDirectory->addChild(new vfsStreamFile('composer.json')); $secondLevelSubDirectory->addChild(new vfsStreamFile('LICENSE')); $secondLevelSubDirectory->addChild(new vfsStreamFile('README.md')); $thirdLevelSubDirectory = new vfsStreamDirectory('Psr'); $secondLevelSubDirectory->addChild($thirdLevelSubDirectory); $fourthLevelSubDirectory = new vfsStreamDirectory('Log'); $thirdLevelSubDirectory->addChild($fourthLevelSubDirectory); $fourthLevelSubDirectory->addChild(new vfsStreamFile('InvalidArgumentException.php')); $fourthLevelSubDirectory->addChild(new vfsStreamFile('LoggerInterface.php')); $fourthLevelSubDirectory->addChild(new vfsStreamFile('LogLevel.php')); $fourthLevelSubDirectory->addChild(new vfsStreamFile('NullLogger.php')); }
/** * @param string $content * * @return string Created file URL */ private function createSettingsFile($content) { $settingsFile = VfsStream::newFile('Settings.php'); $settingsFile->setContent($content); $this->vfsStream->addChild($settingsFile); return $settingsFile->url(); }
public function testAllDirectories() { $this->root->addChild(new vfsStreamDirectory('tmp')); $this->root->addChild(new vfsStreamDirectory('tmp2')); $arr = $this->files->allDirectories($this->root->url()); $this->assertInstanceOf(SplFileInfo::class, $arr[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'); }
/** * @test * @covers Cocur\Bundle\BuildBundle\Command\CleanCommand::__construct() * @covers Cocur\Bundle\BuildBundle\Command\CleanCommand::configure() * @covers Cocur\Bundle\BuildBundle\Command\CleanCommand::execute() * @covers Cocur\Bundle\BuildBundle\Command\CleanCommand::cleanDirectory() */ public function executeShouldOutputDetailedInformationInVerboseMode() { $this->buildDir->addChild(vfsStream::newFile('foo1.txt')); $this->buildDir->addChild($barDir = vfsStream::newDirectory('bar')); $barDir->addChild(vfsStream::newFile('foo2.txt')); $this->filesystem->shouldReceive('remove')->with(sprintf('%s/foo1.txt', $this->buildDir->url()))->once(); $this->filesystem->shouldReceive('remove')->with(sprintf('%s/bar/foo2.txt', $this->buildDir->url()))->once(); $this->filesystem->shouldReceive('remove')->with(sprintf('%s/bar', $this->buildDir->url()))->once(); $command = $this->application->find('cocur:clean'); $commandTester = new CommandTester($command); $commandTester->execute(['command' => $command->getName()], ['verbosity' => 2]); $this->assertRegExp('/Delete:(.*)foo1\\.txt/', $commandTester->getDisplay()); $this->assertRegExp('/Delete:(.*)bar/', $commandTester->getDisplay()); $this->assertRegExp('/Delete:(.*)bar\\/foo2\\.txt/', $commandTester->getDisplay()); $this->assertRegExp('/Removed 3 files from/', $commandTester->getDisplay()); }
/** * @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; }
/** * @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']); }
/** * @test */ public function testReadingFromBoilerplate() { $boilerplate = new vfsStreamFile('boilerplate.yml'); $this->dir->addChild($boilerplate); $this->task->useBoilerplate($boilerplate->url()); $this->reader->expects($this->once())->method('readFromFile')->willReturn(array('foo' => 'bar')); $this->expectOneSerializerCall(array('foo' => 'bar')); $this->task->run(); }
protected function _before() { $this->moduleContainer = $this->prophesize(ModuleContainer::class); $this->root = vfsStream::setup('root'); $wpDir = vfsStream::newDirectory('wp'); $this->root->addChild($wpDir); $this->config = ['path' => $this->root->url() . '/wp']; $this->executor = $this->prophesize(Executor::class); }
/** * @param Manager $manager * * @depends test__construct */ public function testCheckImage(Manager $manager) { $structure = array("app" => array(), "web" => array("uploads" => array('somefile' => 'somecontent'))); $structureStream = vfsStream::create($structure); $this->root->addChild($structureStream); $method = new \ReflectionMethod($manager, 'checkImage'); $method->setAccessible(true); $method->invoke($manager, 'uploads/somefile'); $method->invoke($manager, 'vfs://web/uploads/somefile'); $this->assertTrue(true); }
function it_can_upload_a_payload_to_an_existing_document(HttpAdapter $httpAdapter) { $file = vfsStream::newFile('file'); $file->setContent('somecontent'); $this->tempDir->addChild($file); $file = fopen('vfs://path/file', 'r'); $expected = []; $request = ['document[file]' => $file, 'access_token' => 'myapitoken']; $httpAdapter->post('documents/a1ec0371-966d-11e4-baee-08002730eb8a/payload', $request, [], HttpAdapter::RETURN_TYPE_JSON)->willReturn($expected); $this->uploadDocument('a1ec0371-966d-11e4-baee-08002730eb8a', $file)->shouldReturn($expected); }
/** * @covers ::pruneChunks */ public function testUploader_pruneChunks() { //// Setup test $newDir = vfsStream::newDirectory('1'); $newDir->lastModified(time() - 31); $newDir->lastModified(time()); $fileFirst = vfsStream::newFile('file31'); $fileFirst->lastModified(time() - 31); $fileSecond = vfsStream::newFile('random_file'); $fileSecond->lastModified(time() - 30); $upDir = vfsStream::newFile('..'); $this->vfs->addChild($newDir); $this->vfs->addChild($fileFirst); $this->vfs->addChild($fileSecond); $this->vfs->addChild($upDir); //// Actual test Uploader::pruneChunks($this->vfs->url(), 30); $this->assertTrue(file_exists($newDir->url())); $this->assertFalse(file_exists($fileFirst->url())); $this->assertTrue(file_exists($fileSecond->url())); }
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; }
/** * @throws \WPluginCore003\Diagnostics\Exception * @author Panagiotis Vagenas <*****@*****.**> * @since 0.0.2 */ public function testTruePath() { $cases = array(array('original' => '/1/2/3/4/5/file', 'expected' => '/1/2/3/4/5/file'), array('original' => '/1/2/3/../4/5/file', 'expected' => '/1/2/4/5/file'), array('original' => '/1/2/3/../../4/5/file', 'expected' => '/1/4/5/file'), array('original' => '/1/2/3/../../../../4/5/file', 'expected' => realpath(getcwd() . '/../') . '/4/5/file'), array('original' => '/1/2/3/../../../../4/5/../file', 'expected' => realpath(getcwd() . '/../') . '/4/file'), array('original' => '/1/2/3/../../../../4/5/../../file', 'expected' => realpath(getcwd() . '/../') . '/file'), array('original' => '/1/2/3/../../../../../4/5/../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/../../../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1///2/./3/../../../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/..///./..///../../4/5/../../../file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/1/2/3/../../../../4/./././5/../../..///./file', 'expected' => realpath(getcwd() . '/../../') . '/file'), array('original' => '/root/dir', 'expected' => '/root/dir'), array('original' => '/root/dir/', 'expected' => '/root/dir'), array('original' => '/root/dir/subDir/../', 'expected' => '/root/dir'), array('original' => '//root/dir///subDir/..///', 'expected' => '/root/dir'), array('original' => '/root/dir', 'expected' => '/root/dir'), array('original' => '/root/dir/', 'expected' => '/root/dir'), array('original' => '/root/dir/subDir/../', 'expected' => '/root/dir'), array('original' => '//root/dir///subDir/..///', 'expected' => '/root/dir'), array('original' => '://root/dir///subDir/..///', 'expected' => '://root/dir'), array('original' => 'vfs://root/dir///subDir/..///', 'expected' => 'vfs://root/dir')); $rootDir = new vfs\vfsStreamDirectory('root'); $rdDir = new vfs\vfsStreamDirectory('dir'); $rdSubDir = new vfs\vfsStreamDirectory('subDir'); $rootDir->addChild($rdDir); $rdDir->addChild($rdSubDir); vfs\vfsStreamWrapper::setRoot($rootDir); foreach ($cases as $i => $case) { $this->assertSame($case['expected'], \WPluginCore003\Plugin\Paths::truePath($case['original']), 'Failure on case ' . ($i + 1) . ' ---> "' . implode('" => "', $case) . '"'); } }
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; }
/** * 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"); }