-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[TwigBundle] Added priority to twig extensions #24777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9658556
65cc813
0d77f49
54d30b1
3d5a545
1cf78d2
a22d713
65f4e89
a00ffad
ff
8000
2aba2
9e8d1f5
5399083
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class TwigEnvironmentPassTest extends TestCase | ||
{ | ||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for clarity i prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK, we don't do much "inline" on properties. |
||
*/ | ||
private $builder; | ||
/** | ||
* @var Definition | ||
*/ | ||
private $definition; | ||
/** | ||
* @var TwigEnvironmentPass | ||
*/ | ||
private $pass; | ||
|
||
protected function setUp() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need this method IMHO, better remove it and the corresponding properties There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done :) |
||
{ | ||
$this->builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'setAlias', 'getDefinition'))->getMock(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would not mock the
<
10387
/div>
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I based it on this test: https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php#L36 I can change it to use the actual builder if you'd like? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please do so :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xabbuh done :) |
||
$this->definition = new Definition('twig'); | ||
$this->pass = new TwigEnvironmentPass(); | ||
} | ||
|
||
public function testPassWithTwoExtensionsWithPriority() | ||
{ | ||
$serviceIds = array( | ||
'test_extension_1' => array( | ||
array('priority' => 100), | ||
), | ||
'test_extension_2' => array( | ||
array('priority' => 200), | ||
), | ||
); | ||
|
||
$this->builder->expects($this->once()) | ||
->method('hasDefinition') | ||
->with('twig') | ||
->will($this->returnValue(true)); | ||
$this->builder->expects($this->once()) | ||
->method('findTaggedServiceIds') | ||
->with('twig.extension') | ||
->will($this->returnValue($serviceIds)); | ||
$this->builder->expects($this->once()) | ||
->method('getDefinition') | ||
->with('twig') | ||
->will($this->returnValue($this->definition)); | ||
|
||
$this->pass->process($this->builder); | ||
$calls = $this->definition->getMethodCalls(); | ||
$this->assertCount(2, $calls); | ||
$this->assertEquals('addExtension', $calls[0][0]); | ||
$this->assertEquals('addExtension', $calls[1][0]); | ||
$this->assertEquals('test_extension_2', (string) $calls[0][1][0]); | ||
$this->assertEquals('test_extension_1', (string) $calls[1][1][0]); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be replaced by using the
PriorityTaggedServiceTrait
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iltar done :)