/** * visit a directory and process it * * @param vfsStreamDirectory $dir * @return vfsStreamStructureVisitor */ public function visitDirectory(vfsStreamDirectory $dir) { $this->current[$dir->getName()] = array(); $tmp =& $this->current; $this->current =& $tmp[$dir->getName()]; foreach ($dir as $child) { $this->visit($child); } $this->current =& $tmp; return $this; }
public function testGetProjectRoot() { $tempDir = $this->root->getName(); $testDir = tempnam($tempDir, ''); unlink($testDir); mkdir("{$testDir}/1/2/3/4/5", 0755, true); $expectedRoot = "{$testDir}/1"; touch("{$expectedRoot}/.platform-project"); chdir($testDir); $this->assertFalse(LocalProject::getProjectRoot()); chdir($expectedRoot); $this->assertEquals($expectedRoot, LocalProject::getProjectRoot()); chdir("{$testDir}/1/2/3/4/5"); $this->assertEquals($expectedRoot, LocalProject::getProjectRoot()); }
/** * visit a directory and process it * * @param vfsStreamDirectory $dir * @return vfsStreamPrintVisitor */ public function visitDirectory(vfsStreamDirectory $dir) { $this->printContent($dir->getName()); $this->depth++; foreach ($dir as $child) { $this->visit($child); } $this->depth--; return $this; }
/** * @param string $sourceDir * * @return string */ protected function createDummyProject($sourceDir) { if (!is_dir($sourceDir)) { throw new \InvalidArgumentException("Not a directory: {$sourceDir}"); } $tempDir = self::$root->getName(); $projectRoot = tempnam($tempDir, ''); unlink($projectRoot); mkdir($projectRoot); // Set up the project files. $local = new LocalProject(); $local->createProjectFiles($projectRoot, 'testProjectId'); // Make a dummy repository. $repositoryDir = $projectRoot . '/' . LocalProject::REPOSITORY_DIR; mkdir($repositoryDir); $fsHelper = new FilesystemHelper(); $fsHelper->copyAll($sourceDir, $repositoryDir); return $projectRoot; }
/** * 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(); vfsStream::copyFromFileSystem(__DIR__ . '/../fixtures/images', $this->dir); $dir = $this->dir; $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)); $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->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)))); $this->provider = new ImageProvider(vfsStream::url($this->dir->getName()) . '/', $imagine); }
/** * Create a test directory with a unique name. * * @param bool $fill Fill the directory with some files. * * @return string */ protected function tempDir($fill = false) { $tempDir = $this->root->getName(); $testDir = tempnam($tempDir, ''); unlink($testDir); mkdir($testDir); if ($fill) { touch($testDir . '/test-file'); mkdir($testDir . '/test-dir'); touch($testDir . '/test-dir/test-file'); mkdir($testDir . '/test-nesting/1/2/3', 0755, true); touch($testDir . '/test-nesting/1/2/3/test-file'); } return $testDir; }