|
3
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the FOSUserBundle package. |
|
|
5 |
* |
|
|
6 |
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
|
7 |
* |
|
|
8 |
* For the full copyright and license information, please view the LICENSE |
|
|
9 |
* file that was distributed with this source code. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace FOS\UserBundle\Tests\DependencyInjection\Compiler; |
|
|
13 |
|
|
|
14 |
use FOS\UserBundle\DependencyInjection\Compiler\SecurityEncoderFactoryPass; |
|
|
15 |
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
16 |
use Symfony\Component\DependencyInjection\Definition; |
|
|
17 |
|
|
|
18 |
class SecurityEncoderFactoryPassTest extends \PHPUnit_Framework_TestCase |
|
|
19 |
{ |
|
|
20 |
private $container; |
|
|
21 |
private $pass; |
|
|
22 |
|
|
|
23 |
public function setUp() |
|
|
24 |
{ |
|
|
25 |
$this->container = new ContainerBuilder(); |
|
|
26 |
$this->pass = new SecurityEncoderFactoryPass(); |
|
|
27 |
} |
|
|
28 |
|
|
|
29 |
public function testShouldComposeAlias() |
|
|
30 |
{ |
|
|
31 |
$this->container->setDefinition('security.encoder_factory.real', new Definition()); |
|
|
32 |
$this->container->setAlias('security.encoder_factory', 'security.encoder_factory.real'); |
|
|
33 |
|
|
|
34 |
$this->pass->process($this->container); |
|
|
35 |
|
|
|
36 |
$this->assertServiceHasAlias('security.encoder_factory.real', 'fos_user.encoder_factory.parent'); |
|
|
37 |
$this->assertFalse($this->container->getAlias('fos_user.encoder_factory.parent')->isPublic()); |
|
|
38 |
$this->assertServiceHasAlias('fos_user.encoder_factory', 'security.encoder_factory'); |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
public function testShouldComposeDefinition() |
|
|
42 |
{ |
|
|
43 |
$this->container->setDefinition('security.encoder_factory', $originalDefinition = new Definition()); |
|
|
44 |
|
|
|
45 |
$this->pass->process($this->container); |
|
|
46 |
|
|
|
47 |
$newDefinition = $this->container->getDefinition('fos_user.encoder_factory.parent'); |
|
|
48 |
$this->assertFalse($newDefinition->isPublic()); |
|
|
49 |
$this->assertSame($originalDefinition, $newDefinition); |
|
|
50 |
|
|
|
51 |
$this->assertServiceHasAlias('fos_user.encoder_factory', 'security.encoder_factory'); |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
private function assertServiceHasAlias($serviceId, $aliasId) |
|
|
55 |
{ |
|
|
56 |
$this->assertEquals($serviceId, (string) $this->container->getAlias($aliasId), sprintf('Service "%s" has alias "%s"', $serviceId, $aliasId)); |
|
|
57 |
} |
|
|
58 |
} |