Last active
September 13, 2015 09:43
-
-
Save ciaranmcnulty/99402a8665ef19eeccc5 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace spec\League\Event; | |
use Interop\Container\ContainerInterface; | |
use Interop\Container\Exception\ContainerException; | |
use League\Event\EventInterface; | |
use League\Event\ListenerInterface; | |
use PhpSpec\ObjectBehavior; | |
use Prophecy\Argument; | |
class LazyListenerSpec extends ObjectBehavior | |
{ | |
function let( | |
ContainerInterface $container, | |
ListenerInterface $actualListener | |
) | |
{ | |
$this->beConstructedFromAlias('listener-alias', $container); | |
$container->get('listener-alias')->willReturn($actualListener); | |
} | |
function it_is_a_valid_listener() | |
{ | |
$this->shouldHaveType('League\Event\ListenerInterface'); | |
} | |
function it_identifies_as_itself() | |
{ | |
$this->isListener($this->getWrappedObject())->shouldReturn(true); | |
} | |
function it_identifies_as_the_wrapped_listener( | |
ListenerInterface $actualListener | |
) | |
{ | |
$this->isListener($actualListener)->shouldReturn(true); | |
} | |
function it_throws_an_exception_when_container_does_not_contain_listener( | |
ContainerInterface $container, | |
EventInterface $event | |
) | |
{ | |
$container->get('listener-alias')->willThrow(new ContainerException('oops')); | |
$this->shouldThrow(\BadMethodCallException::class)->duringHandle($event); | |
} | |
function it_throws_an_exception_when_listener_is_not_correct_type( | |
ContainerInterface $container, | |
EventInterface $event | |
) | |
{ | |
$container->get('listener-alias')->willReturn(new \StdClass()); | |
$this->shouldThrow(\BadMethodCallException::class)->duringHandle($event); | |
} | |
function it_lets_actual_listener_handle_an_event( | |
EventInterface $event, | |
ListenerInterface $actualListener | |
) { | |
$this->handle($event); | |
$actualListener->handle($event)->shouldHaveBeenCalled(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment