Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of kernel.event_subscriber tag for services.
- Loading branch information
Showing
4 changed files
with
173 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...le/FrameworkBundle/Tests/DependencyInjection/Compiler/RegisterKernelListenersPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?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\FrameworkBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RegisterKernelListenersPass; | ||
|
||
class RegisterKernelListenersPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* Tests that event subscribers not implementing EventSubscriberInterface | ||
* trigger an exception. | ||
* | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testEventSubscriberWithoutInterface() | ||
{ | ||
// one service, not implementing any interface | ||
$services = array( | ||
'my_event_subscriber' => array(0 => array()), | ||
); | ||
|
||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$definition->expects($this->atLeastOnce()) | ||
->method('getClass') | ||
->will($this->returnValue('stdClass')); | ||
|
||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); | ||
$builder->expects($this->any()) | ||
->method('hasDefinition') | ||
->will($this->returnValue(true)); | ||
|
||
// We don't test kernel.event_listener here | ||
$builder->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->onConsecutiveCalls(array(), $services)); | ||
|
||
$builder->expects($this->atLeastOnce()) | ||
->method('getDefinition') | ||
->will($this->returnValue($definition)); | ||
|
||
$registerListenersPass = new RegisterKernelListenersPass(); | ||
$registerListenersPass->process($builder); | ||
} | ||
|
||
public function testValidEventSubscriber() | ||
{ | ||
$services = array( | ||
'my_event_subscriber' => array(0 => array()), | ||
); | ||
|
||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); | ||
$definition->expects($this->atLeastOnce()) | ||
->method('getClass') | ||
->will($this->returnValue('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\SubscriberService')); | ||
|
||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); | ||
$builder->expects($this->any()) | ||
->method('hasDefinition') | ||
->will($this->returnValue(true)); | ||
|
||
// We don't test kernel.event_listener here | ||
$builder->expects($this->atLeastOnce()) | ||
->method('findTaggedServiceIds') | ||
->will($this->onConsecutiveCalls(array(), $services)); | ||
|
||
$builder->expects($this->atLeastOnce()) | ||
->method('getDefinition') | ||
->will($this->returnValue($definition)); | ||
|
||
$registerListenersPass = new RegisterKernelListenersPass(); | ||
$registerListenersPass->process($builder); | ||
} | ||
} | ||
|
||
class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface | ||
{ | ||
static function getSubscribedEvents() {} | ||
} |