fix for legacy asset() with EmptyVersionStrategy

This commit is contained in:
Christian Flothmann 2015-07-02 23:04:32 +02:00
parent 2217c1faec
commit cf86a03b98
2 changed files with 19 additions and 4 deletions

View File

@ -108,11 +108,15 @@ class AssetExtension extends \Twig_Extension
$v->setAccessible(true);
$currentVersionStrategy = $v->getValue($package);
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);
$format = $f->getValue($currentVersionStrategy);
if (property_exists($currentVersionStrategy, 'format')) {
$f = new \ReflectionProperty($currentVersionStrategy, 'format');
$f->setAccessible(true);
$format = $f->getValue($currentVersionStrategy);
$v->setValue($package, new StaticVersionStrategy($version, $format));
$v->setValue($package, new StaticVersionStrategy($version, $format));
} else {
$v->setValue($package, new StaticVersionStrategy($version));
}
}
try {

View File

@ -15,6 +15,7 @@ use Symfony\Bridge\Twig\Extension\AssetExtension;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
class AssetExtensionTest extends \PHPUnit_Framework_TestCase
@ -41,6 +42,16 @@ class AssetExtensionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('/foo/me.png?version=42', $extension->getAssetUrl('me.png', null, false, 42));
}
/**
* @group legacy
*/
public function testGetAssetUrlWithEmptyVersionStrategy()
{
$extension = $this->createExtension(new PathPackage('foo', new EmptyVersionStrategy()));
$this->assertEquals('/foo/me.png?42', $extension->getAssetUrl('me.png', null, false, 42));
}
private function createExtension(Package $package)
{
$foundationExtension = $this->getMockBuilder('Symfony\Bridge\Twig\Extension\HttpFoundationExtension')->disableOriginalConstructor()->getMock();