예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function _setUpFiles($structure = NULL)
 {
     $structure = $structure ?: ['tmp' => []];
     $this->root = vfsStream::setup('root', 0777, $structure);
     $this->adapter = new TempFileAdapter($this->root->url() . '/tmp/', 'bmtest_');
     $this->manager = new TempFileManager($this->adapter);
 }
예제 #2
0
 /**
  * @param string $className
  * @dataProvider provider
  */
 public function testGeneratesTestCodeCorrectly($className)
 {
     $generatedFile = vfsStream::url('root') . '/' . $className . 'Test.php';
     $generator = new TestGenerator($className, __DIR__ . '/_fixture/_input/' . $className . '.php', $className . 'Test', $generatedFile);
     $generator->write();
     $this->assertStringMatchesFormatFile(__DIR__ . '/_fixture/_expected/' . $className . 'Test.php', file_get_contents($generatedFile));
 }
 function it_creates_internal_io_factory_with_vfs_stream()
 {
     $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.vfs')->willReturn(vfsStream::setup('custom_root_dir'));
     $factory = $this->ioFactory();
     $factory->shouldImplement(\Closure::class);
     $factory($this->serviceContainer)->shouldImplement(Io::class);
 }
예제 #4
0
 /**
  * We ignore items that are not covered by the map.
  */
 public function testLoadUncovered()
 {
     vfsStream::setup('StaticMapTestLoadUncovered', null, ['a.php' => '<?php']);
     $object = new StaticMap(['A' => vfsStream::url('a.php'), 'B' => vfsStream::url('Covered.php')]);
     $object->load('StaticMapTestLoadUncoveredC_XYZ');
     $this->assertFalse(class_exists('StaticMapTestLoadUncoveredC_XYZ', false));
 }
예제 #5
0
 /**
  * Provides Mutex factories.
  *
  * @return callable[][] The mutex factories.
  */
 public function provideMutexFactories()
 {
     $cases = ["NoMutex" => [function () {
         return new NoMutex();
     }], "TransactionalMutex" => [function () {
         $pdo = new \PDO("sqlite::memory:");
         $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
         return new TransactionalMutex($pdo);
     }], "FlockMutex" => [function () {
         vfsStream::setup("test");
         return new FlockMutex(fopen(vfsStream::url("test/lock"), "w"));
     }], "SemaphoreMutex" => [function () {
         return new SemaphoreMutex(sem_get(ftok(__FILE__, "a")));
     }], "SpinlockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(SpinlockMutex::class, ["test"]);
         $mock->expects($this->any())->method("acquire")->willReturn(true);
         $mock->expects($this->any())->method("release")->willReturn(true);
         return $mock;
     }], "LockMutex" => [function () {
         $mock = $this->getMockForAbstractClass(LockMutex::class);
         $mock->expects($this->any())->method("lock")->willReturn(true);
         $mock->expects($this->any())->method("unlock")->willReturn(true);
         return $mock;
     }]];
     if (getenv("MEMCACHE_HOST")) {
         $cases["MemcacheMutex"] = [function () {
             $memcache = new Memcache();
             $memcache->connect(getenv("MEMCACHE_HOST"));
             return new MemcacheMutex("test", $memcache);
         }];
         $cases["MemcachedMutex"] = [function () {
             $memcache = new Memcached();
             $memcache->addServer(getenv("MEMCACHE_HOST"), 11211);
             return new MemcachedMutex("test", $memcache);
         }];
     }
     if (getenv("REDIS_URIS")) {
         $uris = explode(",", getenv("REDIS_URIS"));
         $cases["PredisMutex"] = [function () use($uris) {
             $clients = array_map(function ($uri) {
                 return new Client($uri);
             }, $uris);
             return new PredisMutex($clients, "test");
         }];
         $cases["PHPRedisMutex"] = [function () use($uris) {
             $apis = array_map(function ($uri) {
                 $redis = new Redis();
                 $uri = parse_url($uri);
                 if (!empty($uri["port"])) {
                     $redis->connect($uri["host"], $uri["port"]);
                 } else {
                     $redis->connect($uri["host"]);
                 }
                 return $redis;
             }, $uris);
             return new PHPRedisMutex($apis, "test");
         }];
     }
     return $cases;
 }
예제 #6
0
    /**
     * {@inheritdoc}
     */
    public function testLoad()
    {
        $xml = <<<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<mediatypes>
    <mediatype name="mp4" category="video">
        <mimetypes>
            <mimetype>video/mp4</mimetype>
        </mimetypes>
    </mediatype>
    <mediatype name="jpg" category="image">
        <mimetypes>
            <mimetype>image/jpg</mimetype>
            <mimetype>image/jpeg</mimetype>
        </mimetypes>
    </mediatype>
</mediatypes>
EOF;
        vfsStream::setup('root', null, ['types.xml' => $xml]);
        $mediatypes = $this->loader->load(vfsStream::url('root/types.xml'));
        $this->assertCount(2, $mediatypes);
        $this->assertTrue($mediatypes->has('video:mp4'));
        $this->assertSame('mp4', $mediatypes->get('video:mp4')->getName());
        $this->assertSame('video', $mediatypes->get('video:mp4')->getCategory());
        $this->assertCount(1, $mediatypes->get('video:mp4')->getMimetypes());
        $this->assertSame(['video/mp4'], $mediatypes->get('video:mp4')->getMimetypes());
        $this->assertTrue($mediatypes->has('image:jpg'));
        $this->assertSame('jpg', $mediatypes->get('image:jpg')->getName());
        $this->assertSame('image', $mediatypes->get('image:jpg')->getCategory());
        $this->assertCount(2, $mediatypes->get('image:jpg')->getMimetypes());
        $this->assertSame(['image/jpg', 'image/jpeg'], $mediatypes->get('image:jpg')->getMimetypes());
    }
예제 #7
0
 /**
  * @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());
 }
예제 #8
0
 /**
  * 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);
 }
예제 #9
0
 /**
  * This test creates an extension based on a JSON file, generated
  * with version 1.0 of the ExtensionBuilder and compares all
  * generated files with the originally created ones
  * This test should help, to find compatibility breaking changes
  *
  * @test
  */
 function generateExtensionFromVersion3Configuration()
 {
     $this->configurationManager = $this->getMock($this->buildAccessibleProxy('EBT\\ExtensionBuilder\\Configuration\\ConfigurationManager'), array('dummy'));
     $this->extensionSchemaBuilder = $this->objectManager->get('EBT\\ExtensionBuilder\\Service\\ExtensionSchemaBuilder');
     $testExtensionDir = $this->fixturesPath . 'TestExtensions/test_extension_v3/';
     $jsonFile = $testExtensionDir . \EBT\ExtensionBuilder\Configuration\ConfigurationManager::EXTENSION_BUILDER_SETTINGS_FILE;
     if (file_exists($jsonFile)) {
         // compatibility adaptions for configurations from older versions
         $extensionConfigurationJSON = json_decode(file_get_contents($jsonFile), TRUE);
         $extensionConfigurationJSON = $this->configurationManager->fixExtensionBuilderJSON($extensionConfigurationJSON, FALSE);
     } else {
         $extensionConfigurationJSON = array();
         $this->fail('JSON file not found');
     }
     $this->extension = $this->extensionSchemaBuilder->build($extensionConfigurationJSON);
     $this->fileGenerator->setSettings(array('codeTemplateRootPath' => PATH_typo3conf . 'ext/extension_builder/Resources/Private/CodeTemplates/Extbase/', 'extConf' => array('enableRoundtrip' => '0')));
     $newExtensionDir = vfsStream::url('testDir') . '/';
     $this->extension->setExtensionDir($newExtensionDir . 'test_extension/');
     $this->fileGenerator->build($this->extension);
     $referenceFiles = \TYPO3\CMS\Core\Utility\GeneralUtility::getAllFilesAndFoldersInPath(array(), $testExtensionDir);
     foreach ($referenceFiles as $referenceFile) {
         $createdFile = str_replace($testExtensionDir, $this->extension->getExtensionDir(), $referenceFile);
         if (!in_array(basename($createdFile), array('ExtensionBuilder.json'))) {
             $referenceFileContent = str_replace(array('2011-08-11T06:49:00Z', '2011-08-11', '###YEAR###', '2014'), array(date('Y-m-d\\TH:i:00\\Z'), date('Y-m-d'), date('Y'), date('Y')), file_get_contents($referenceFile));
             $this->assertFileExists($createdFile, 'File ' . $createdFile . ' was not created!');
             // do not compare files that contain a formatted DateTime, as it might have changed between file creation and this comparison
             if (strpos($referenceFile, 'xlf') === FALSE && strpos($referenceFile, 'yaml') === FALSE) {
                 $originalLines = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, $referenceFileContent, TRUE);
                 $generatedLines = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(LF, file_get_contents($createdFile), TRUE);
                 $this->assertEquals($originalLines, $generatedLines, 'File ' . $createdFile . ' was not equal to original file.');
             }
         }
     }
 }
 public function testWriteFailsWhenThereIsAProblemWithSymfonyYamlDumper()
 {
     $yamlWriterProvider = new YamlWriterProvider($this->mockWriter);
     $this->mockWriter->expects($this->once())->method('dump')->with(array('result' => false))->willThrowException(new DumpException());
     $this->setExpectedException('JGimeno\\TaskReporter\\Infrastructure\\Exception\\YamlProviderException');
     $yamlWriterProvider->write(vfsStream::url('settings/config.yml'), array('result' => false));
 }
 /**
  * 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);
 }
예제 #12
0
파일: CopyTest.php 프로젝트: toxygene/pants
 /**
  * Setup the test
  */
 public function setUp()
 {
     vfsStream::setup('root', null, array('test' => 'testing'));
     $this->file = vfsStream::url('root/test');
     $this->properties = $this->getMock('\\Pants\\Property\\Properties');
     $this->task = new Copy($this->properties);
 }
예제 #13
0
    /**
     * @covers phpDocumentor\Plugin\Core\Transformer\Writer\CheckStyle::transform
     */
    public function testTransform()
    {
        $transformer = m::mock('phpDocumentor\\Transformer\\Transformation');
        $transformer->shouldReceive('getTransformer->getTarget')->andReturn(vfsStream::url('CheckStyleTest'));
        $transformer->shouldReceive('getArtifact')->andReturn('artifact.xml');
        $fileDescriptor = m::mock('phpDocumentor\\Descriptor\\FileDescriptor');
        $projectDescriptor = m::mock('phpDocumentor\\Descriptor\\ProjectDescriptor');
        $projectDescriptor->shouldReceive('getFiles->getAll')->andReturn(array($fileDescriptor));
        $error = m::mock('phpDocumentor\\Descriptor\\Validator\\Error');
        $fileDescriptor->shouldReceive('getPath')->andReturn('/foo/bar/baz');
        $fileDescriptor->shouldReceive('getAllErrors->getAll')->andReturn(array($error));
        $error->shouldReceive('getLine')->andReturn(1234);
        $error->shouldReceive('getCode')->andReturn(5678);
        $error->shouldReceive('getSeverity')->andReturn('error');
        $error->shouldReceive('getContext')->andReturn('myContext');
        $this->translator->shouldReceive('translate')->with('5678')->andReturn('5678 %s');
        // Call the actual method
        $this->checkStyle->transform($projectDescriptor, $transformer);
        // Assert file exists
        $this->assertTrue($this->fs->hasChild('artifact.xml'));
        // Inspect XML
        $xml = <<<XML
<?xml version="1.0"?>
<checkstyle version="1.3.0">
  <file name="/foo/bar/baz">
    <error line="1234" severity="error" message="5678 myContext" source="phpDocumentor.file.5678"/>
  </file>
</checkstyle>
XML;
        $expectedXml = new \DOMDocument();
        $expectedXml->loadXML($xml);
        $actualXml = new \DOMDocument();
        $actualXml->load(vfsStream::url('CheckStyleTest/artifact.xml'));
        $this->assertEqualXMLStructure($expectedXml->firstChild, $actualXml->firstChild, true);
    }
 /**
  */
 public function setUp()
 {
     ComposerUtility::flushCaches();
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder(\Neos\Flow\Package\PackageManager::class)->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), true);
 }
 protected function setUp()
 {
     $file = vfsStream::newFile('template');
     $this->fileSystem = vfsStream::setup();
     $this->fileSystem->addChild($file);
     $this->filePath = $file->url();
 }
예제 #16
0
 public function testFactoryIpFilter()
 {
     $this->init(array('logger' => array($this->key => array('path' => vfsStream::url('logs/default.log'), 'ip' => '255.*'))));
     $logger = $this->factory->createServiceWithName($this->serviceLocator, $this->key, $this->key);
     $logger->debug('Test');
     $this->assertEquals("", file_get_contents(vfsStream::url('logs/default.log')));
 }
 /**
  * @test
  */
 public function directoryIsCreated()
 {
     $example = new Example('id');
     $this->assertFalse($this->root->hasChild('id'));
     $example->setDirectory(vfsStream::url('exampleDir'));
     $this->assertTrue($this->root->hasChild('id'));
 }
예제 #18
0
 /**
  * Tests the YAML file discovery.
  */
 public function testDiscovery()
 {
     vfsStreamWrapper::register();
     $root = new vfsStreamDirectory('modules');
     vfsStreamWrapper::setRoot($root);
     $url = vfsStream::url('modules');
     mkdir($url . '/test_1');
     file_put_contents($url . '/test_1/test_1.test.yml', 'name: test');
     file_put_contents($url . '/test_1/test_2.test.yml', 'name: test');
     mkdir($url . '/test_2');
     file_put_contents($url . '/test_2/test_3.test.yml', 'name: test');
     // Write an empty YAML file.
     file_put_contents($url . '/test_2/test_4.test.yml', '');
     // Set up the directories to search.
     $directories = array('test_1' => $url . '/test_1', 'test_2' => $url . '/test_1', 'test_3' => $url . '/test_2', 'test_4' => $url . '/test_2');
     $discovery = new YamlDiscovery('test', $directories);
     $data = $discovery->findAll();
     $this->assertEquals(count($data), count($directories));
     $this->assertArrayHasKey('test_1', $data);
     $this->assertArrayHasKey('test_2', $data);
     $this->assertArrayHasKey('test_3', $data);
     $this->assertArrayHasKey('test_4', $data);
     foreach (array('test_1', 'test_2', 'test_3') as $key) {
         $this->assertArrayHasKey('name', $data[$key]);
         $this->assertEquals($data[$key]['name'], 'test');
     }
     $this->assertSame(array(), $data['test_4']);
 }
예제 #19
0
파일: RealTest.php 프로젝트: rickselby/nbt
 public function setUp()
 {
     $this->service = new \Nbt\Service(new \Nbt\DataHandler());
     $this->vRoot = vfsStream::setup();
     $this->vFile = new vfsStreamFile('test.nbt');
     $this->vRoot->addChild($this->vFile);
 }
 /**
  */
 public function setUp()
 {
     vfsStream::setup('Packages');
     $this->mockPackageManager = $this->getMockBuilder('TYPO3\\Flow\\Package\\PackageManager')->disableOriginalConstructor()->getMock();
     ObjectAccess::setProperty($this->mockPackageManager, 'composerManifestData', array(), TRUE);
     $this->packageFactory = new PackageFactory($this->mockPackageManager);
 }
 public function testRemove()
 {
     $strategy = $this->getMockForAbstractClass('Corley\\MaintenanceBundle\\Maintenance\\Strategy\\BaseStrategy');
     file_put_contents(vfsStream::url('web/a'), "MAINTENANCE");
     $strategy->remove(vfsStream::url('web/a'));
     $this->assertFalse(file_exists(vfsStream::url('web/a')));
 }
예제 #22
0
 function let(ParserInterface $parser, FileChecksumInterface $fileChecksum)
 {
     $this->parser = $parser;
     $this->fileChecksum = $fileChecksum;
     $this->vfs = vfsStream::setup('root', null, ['dummy_file1.txt' => 'some_file_content1']);
     $this->beConstructedWith($parser, $this->vfs->url() . '/dummy_file1.txt', $this->fileChecksum);
 }
예제 #23
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);
 }
예제 #24
0
 /**
  * @test
  */
 public function testThrowsExceptionIfTargetDirectoryExists()
 {
     $instance = new ExtensionGenerator();
     $instance->setTargetFolder(vfsStream::url('temp'));
     $this->setExpectedException('RuntimeException');
     $instance->generate();
 }
예제 #25
0
 /**
  * Sets up the test fixture.
  *
  * @return void
  */
 public function setUp()
 {
     vfsStreamWrapper::register();
     vfsStreamWrapper::setRoot(new vfsStreamDirectory('test'));
     $this->forum = 'test';
     $this->contents = new Forum_Contents(vfsStream::url('test'));
 }
예제 #26
0
 /**
  * Try to load a class that is outside the namespace.
  */
 public function testLoadOutside()
 {
     vfsStream::setup('root', null, ['NS' => ['A' => ['B.php' => '<?php class BPSRLoadExists_XYZ {}', 'C.php' => '<?php']]]);
     $object = new PSR0Namespace(vfsStream::url('root'), 'NS');
     $object->load('NS\\A\\D');
     $this->assertFalse(class_exists('NS\\A\\D', false));
 }
 /**
  * @test
  */
 public function visitRecursiveDirectoryStructure()
 {
     $root = vfsStream::setup('root', null, array('test' => array('foo' => array('test.txt' => 'hello'), 'baz.txt' => 'world'), 'foo.txt' => ''));
     $printVisitor = new vfsStreamPrintVisitor(fopen('vfs://root/foo.txt', 'wb'));
     $this->assertSame($printVisitor, $printVisitor->visitDirectory($root));
     $this->assertEquals("- root\n  - test\n    - foo\n      - test.txt\n    - baz.txt\n  - foo.txt\n", file_get_contents('vfs://root/foo.txt'));
 }
예제 #28
0
 /**
  * @test
  * @param array $structure
  * @param array $excludePattern
  * @param array $expected
  * @dataProvider getChecksumsForPathReturnsChecksumForFilesDataProvider
  */
 public function getChecksumsForPathReturnsChecksumForFiles(array $structure, array $excludePattern, array $expected)
 {
     $baseDirectory = vfsStream::url($this->baseDirectory);
     $this->createTestStructure($baseDirectory, $structure);
     $this->assertSame($expected, $this->generator->getChecksumsForPath($baseDirectory, $excludePattern));
     $this->assertSame($expected, $this->generator->getChecksumsForPath($baseDirectory . '/', $excludePattern));
 }
 /**
  * @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')));
 }
 /**
  * Creates the mocked filesystem used in the tests
  */
 public function setUp()
 {
     vfsStream::setup('Foo');
     $this->mockEnvironment = $this->getMock('TYPO3\\Flow\\Utility\\Environment', array(), array(), '', FALSE);
     $this->mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $this->mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(1024));
 }