public function testInvoke() { $path = '/image.jpg'; $packageName = null; $this->packages->expects($this->once())->method('getUrl')->with($path, $packageName); $this->viewHelper->__invoke($path, $packageName); }
public function testAddErrorForInvalidPackageNameType() { $context = ['path' => 'test', 'package' => 456]; $options = [new PropertyPath('path'), new PropertyPath('package')]; $this->function->initialize($options); $message = 'Error message.'; $this->function->setMessage($message); $errors = new ArrayCollection(); $this->packages->expects($this->never())->method('getUrl'); $this->assertSame($context['path'], $this->function->evaluate($context, $errors)); $this->assertCount(1, $errors); $this->assertEquals(['message' => $message, 'parameters' => ['{{ path }}' => 'test', '{{ packageName }}' => 456, '{{ reason }}' => 'Expected null or a string value for the package name, got "integer".']], $errors->get(0)); }
public function testRewrite() { $asset = $this->createAssetMock(); $asset->expects($this->once())->method('getSourceRoot')->will($this->returnValue($sourceRoot = 'source_root')); $asset->expects($this->exactly(2))->method('getSourcePath')->will($this->returnValue($sourcePath = 'source_path')); $asset->expects($this->once())->method('getTargetPath')->will($this->returnValue($targetPath = 'target_path')); $reference = $this->createReference($path = 'foo.jpg'); $this->filesystem->expects($this->once())->method('exists')->with($this->identicalTo($absoluteSourcePath = $sourceRoot . DIRECTORY_SEPARATOR . $path))->will($this->returnValue(true)); $this->namer->expects($this->once())->method('name')->with($this->identicalTo($absoluteSourcePath))->will($this->returnValue($namedFile = 'named_file')); $webTargetPath = DIRECTORY_SEPARATOR . $this->rewriteDirectory . DIRECTORY_SEPARATOR . $namedFile; $this->filesystem->expects($this->once())->method($this->strategy)->with($this->identicalTo($absoluteSourcePath), $this->identicalTo($this->webDirectory . $webTargetPath), $this->isTrue()); $this->packages->expects($this->once())->method('getUrl')->with($this->identicalTo($webTargetPath))->will($this->returnValue($packagedPath = 'packaged_path')); $this->assertSame('url("' . $packagedPath . '")', $this->cssRewriter->rewrite($reference, $asset)); }
public function testGetJsPath() { $this->assetsHelperMock->expects($this->once())->method('getUrl')->with($this->equalTo('foo'))->will($this->returnValue('bar')); $this->assertSame('bar', $this->helper->getJsPath('foo')); }