/** * @since 3.0.0 * @group issue_58 * @test */ public function canEnableFileAnnotationCache() { $root = vfsStream::setup(); $file = vfsStream::newFile('annotations.cache')->withContent(serialize($this->createdCachedAnnotation()))->at($root); persistAnnotationsInFile($file->url()); assertTrue(AnnotationCache::has('foo', 'bar')); }
/** * @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()); }
/** * @test */ public function visitDirectoryWritesDirectoryNameToStream() { $output = vfsStream::newFile('foo.txt')->at(vfsStream::setup()); $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb')); $this->assertSame($printVisitor, $printVisitor->visitDirectory(vfsStream::newDirectory('baz'))); $this->assertEquals("- baz\n", $output->getContent()); }
public function setUp() { vfsStreamWrapper::register(); $root = vfsStream::setup('logs'); $mockFile = vfsStream::newFile('logging_helper.log')->at($root); $root->addChild($mockFile); }
/** * 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); }
/** * @expectedException Respect\Validation\Exceptions\SizeException * @expectedExceptionMessage "vfs://root/1gb.txt" must be greater than 2pb */ public function testShouldThrowsSizeExceptionWhenAsserting() { $root = vfsStream::setup(); $file1Gb = vfsStream::newFile('1gb.txt')->withContent(LargeFileContent::withGigabytes(1))->at($root); $rule = new Size('2pb'); $rule->assert($file1Gb->url()); }
/** * @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)); }
public function testFileReadOnly() { $url = vfsStream::newFile('test', 00)->at($this->_root)->url(); $validator = new DirectoryWritable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(array(DirectoryWritable::DIRECTORY => "'{$url}' ist kein Verzeichnis oder nicht zugänglich"), $validator->getMessages()); }
public function setUp() { $this->root = vfsStream::setup('dir'); $this->file = vfsStream::newFile('stam.yml'); $this->root->addChild($this->file); $this->stamFile = new StamFile($this->root->getChild('stam.yml')->url()); }
public function testCreate_WhenPatternHasLastOnFile_ThrowsException() { vfsStream::newFile('file.csv')->at($this->root); $pathToFile = $this->root->url() . '/file.csv'; $this->setExpectedException('\\InvalidArgumentException'); $this->getFileNameGenerator($pathToFile . ':last')->getGeneratedFileName(); }
public function testDelete_FailToDeleteFile_MustThrow() { $root = vfsStream::setup('root', 0400); vfsStream::newFile('test', 0444)->at($root); $this->expectException('RuntimeException'); Folder::delete($root->url()); }
public function setUp() { $this->root = vfsStream::setup('root', 0777); $this->someFile = vfsStream::newFile('multiline2.txt', 0777); $this->root->addChild($this->someFile); $this->someFile->setContent("LINE1" . PHP_EOL . "LINE2" . PHP_EOL . "LINE3"); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. */ public function setUp() { $dir = vfsStream::setup('invite-codes'); vfsStream::newFile('UNUSED')->at($dir); vfsStream::newFile('USED')->at($dir)->setContent("user@example.com\n2014-12-01T02:15:00+00:00\n"); InviteCode::setDir(vfsStream::url('invite-codes')); }
public function testReadExcludeLines_WhenNoReadPermission_MustNotThrow() { $root = vfsStream::setup(); $file = vfsStream::newFile('.gitignore')->at($root)->setContent('foo'); $finder = DefaultFinder::createIn($root->url()); $this->assertSame(0, $finder->count()); }
/** * @test */ public function importTemporaryFileFixesPermissionsForTemporaryFile() { $mockTempFile = vfsStream::newFile('SomeTemporaryFile', 0333)->withContent('fixture')->at($this->mockDirectory); $this->writableFileSystemStorage->_call('importTemporaryFile', $mockTempFile->url(), 'default'); // dummy assertion to suppress PHPUnit warning $this->assertTrue(TRUE); }
public function testFileNotReadable() { $url = vfsStream::newFile('test', 00)->at($this->_root)->url(); $validator = new FileReadable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(array(FileReadable::READABLE => "Datei '{$url}' ist nicht lesbar"), $validator->getMessages()); }
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 testGeneratePostActivation() { // Touch a new "insert.sql" file and copy a "create.sql" file /** @var \org\bovigo\vfs\vfsStreamFile $file */ $configDir = $this->stream->getChild("Config"); $file = vfsStream::newFile("create.sql")->at($configDir); $file->setContent(file_get_contents(__DIR__ . "/../" . static::TEST_MODULE_PATH . "Config" . DS . "thelia.sql")); vfsStream::newFile("insert.sql")->at($configDir); // Then run the generator $generator = new ModulePhpGenerator($this->getSmarty()); $generator->doGenerate($this->event); // Read the class include $this->getStreamPath("TheliaStudioTestModule.php"); $reflection = new \ReflectionClass("TheliaStudioTestModule\\TheliaStudioTestModule"); $this->assertTrue($reflection->hasConstant("MESSAGE_DOMAIN")); $this->assertEquals("theliastudiotestmodule", $reflection->getConstant("MESSAGE_DOMAIN")); $this->assertTrue($reflection->hasMethod("postActivation")); // get a method closure $method = $reflection->getMethod("postActivation"); $closure = $method->getClosure($reflection->newInstance()); // Test that the table doesn't exist /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */ $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'"); $this->assertEquals(0, $stmt->count()); // Execute the method $closure($this->con); // Now it exists /** @var \Propel\Runtime\DataFetcher\PDODataFetcher $stmt */ $stmt = $this->con->query("SHOW TABLES LIKE 'example_table'"); $this->assertEquals(1, $stmt->count()); }
public function testVirtualizeCanAcceptVfsContentInstances() { $this->virtualSystem->virtualize(['test', vfsStream::newFile('test2'), vfsStream::newDirectory('testDir')]); $this->assertEquals(3, $this->virtualSystem->getFileCount()); $this->assertInstanceOf(vfsStreamDirectory::class, $this->virtualSystem->getFileAtIndex(2)); $this->assertInstanceOf(vfsStreamFile::class, $this->virtualSystem->getFileAtIndex(1)); }
protected function setUp() { $file = vfsStream::newFile('template'); $this->fileSystem = vfsStream::setup(); $this->fileSystem->addChild($file); $this->filePath = $file->url(); }
/** * @expectedException Exception */ public function testLoadCouldNotDecode() { $storage = new EncryptedFilesystemStorage('satoshi'); vfsStream::newFile('public.key')->at($this->root)->setContent('00'); $key = $storage->load(vfsStream::url('tmp/public.key')); $this->assertInstanceOf('Bitpay\\PublicKey', $key); }
public function testFileReadOnly() { $url = vfsStream::newFile('test', 00)->at($this->_root)->url(); $validator = new DirectoryWritable(); $this->assertFalse($validator->isValid($url)); $this->assertEquals(DirectoryWritable::DIRECTORY, key($validator->getMessages())); }
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); }
/** * 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); }
/** * @test */ public function constructWithStringFailsAndThrowsIOException() { vfsStream::newFile('test.txt', 00)->at(vfsStream::setup()); expect(function () { new FileOutputStream($this->fileUrl, 'r'); })->throws(StreamException::class)->withMessage('Can not open file vfs://home/test.txt with mode r:' . ' failed to open stream: "org\\bovigo\\vfs\\vfsStreamWrapper::stream_open"' . ' call failed'); }
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); }
public function test_Should_DeleteFile() { $file = vfsStream::newFile('file')->at($this->rootDir); $fs = new LaravelFilesystem($this->app['files']); $fs->delete(vfsStream::url('rootDir/file')); $this->assertFileNotExists(vfsStream::url('rootDir/file')); }
/** * @test */ public function parse() { vfsStream::newFile('file1', '644')->setContent("test file1")->at($this->root); vfsStream::newFile('file2', '644')->setContent("test file1")->at($this->root); $parser = new DirectoryParser(); $this->assertEquals([['add', 'file1', 'file1'], ['add', 'file2', 'file2']], $parser->parse(vfsStream::url('root'))); }
protected function setUp() { parent::setUp(); vfsStream::setup('application_path')->addChild($configFile = vfsStream::newFile('.travis.yml')); $this->configFile = $configFile->url(); $this->sut = new ConfigWriter(); }