Skip to content

Instantly share code, notes, and snippets.

@ciaranmcnulty
Last active September 13, 2015 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ciaranmcnulty/99402a8665ef19eeccc5 to your computer and use it in GitHub Desktop.
Save ciaranmcnulty/99402a8665ef19eeccc5 to your computer and use it in GitHub Desktop.
<?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