ListenerClassFileSpec   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 12

10 Methods

Rating   Name   Duplication   Size   Complexity  
A it_has_bindings_information() 0 8 1
A it_is_initializable() 0 3 1
A it_have_a_listener_checker() 0 3 1
A it_creates_the_listener_instance() 0 5 1
A it_has_a_file_path() 0 3 1
A it_can_be_serialized() 0 16 3
A is_has_a_class_name() 0 3 1
A it_can_run_a_method_as_listener() 0 5 1
A let() 0 3 1
A it_can_run_class_with_invoke_method() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of slick/event package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\Slick\Event\Application;
11
12
use Prophecy\Exception\Prediction\FailedPredictionException;
13
use Psr\Container\ContainerInterface;
14
use Slick\Event\Application\ListenerClassFile;
15
use PhpSpec\ObjectBehavior;
16
use Slick\Event\Event;
17
use Slick\Event\Test\Application\Listener\ClassListener;
18
use Slick\Event\Test\Application\Listener\InvokerListener;
19
use Slick\Event\Test\Application\Listener\SimpleMethodListener;
20
21
/**
22
 * ListenerClassFileSpec specs
23
 *
24
 * @package spec\Slick\Event\Application
25
 */
26
class ListenerClassFileSpec extends ObjectBehavior
27
{
28
29
    public function let(ContainerInterface $container)
30
    {
31
        $this->beConstructedWith(__DIR__. '/Listener/ClassListener.php', $container);
32
    }
33
34
    function it_is_initializable()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
35
    {
36
        $this->shouldHaveType(ListenerClassFile::class);
37
    }
38
39
    public function it_have_a_listener_checker()
40
    {
41
        $this->isListener()->shouldBe(true);
0 ignored issues
show
Bug introduced by
The method isListener() does not exist on spec\Slick\Event\Application\ListenerClassFileSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $this->/** @scrutinizer ignore-call */ 
42
               isListener()->shouldBe(true);
Loading history...
42
    }
43
44
    public function is_has_a_class_name()
45
    {
46
        $this->className()->shouldBe(ClassListener::class);
0 ignored issues
show
Bug introduced by
The method className() does not exist on spec\Slick\Event\Application\ListenerClassFileSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $this->/** @scrutinizer ignore-call */ 
47
               className()->shouldBe(ClassListener::class);
Loading history...
47
    }
48
49
    public function it_creates_the_listener_instance(ContainerInterface $container)
50
    {
51
        $listener = new ClassListener();
52
        $container->get(ClassListener::class)->shouldBeCalled()->willReturn($listener);
53
        $this->resolveListeners()[0]['listener']->shouldBe($listener);
0 ignored issues
show
Bug introduced by
The method resolveListeners() does not exist on spec\Slick\Event\Application\ListenerClassFileSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $this->/** @scrutinizer ignore-call */ 
54
               resolveListeners()[0]['listener']->shouldBe($listener);
Loading history...
54
    }
55
56
    public function it_can_run_class_with_invoke_method(ContainerInterface $container, Event $event)
57
    {
58
        $this->beConstructedWith(__DIR__. '/Listener/InvokerListener.php', $container);
59
        $container->get(InvokerListener::class)->shouldBeCalled()->willReturn(new InvokerListener());
60
        $this->resolveListeners()[0]['listener']->handle($event)->shouldBe($event);
61
        $this->resolveListeners()[1]['listener']->handle($event)->shouldBe($event);
62
    }
63
64
    public function it_can_run_a_method_as_listener(ContainerInterface $container, Event $event)
65
    {
66
        $this->beConstructedWith(__DIR__. '/Listener/SimpleMethodListener.php', $container);
67
        $container->get(SimpleMethodListener::class)->shouldBeCalled()->willReturn(new SimpleMethodListener());
68
        $this->resolveListeners()[0]['listener']->handle($event)->shouldBe($event);
69
    }
70
71
    public function it_has_bindings_information()
72
    {
73
        $this->bindings()->shouldBe([
0 ignored issues
show
Bug introduced by
The method bindings() does not exist on spec\Slick\Event\Application\ListenerClassFileSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->/** @scrutinizer ignore-call */ 
74
               bindings()->shouldBe([
Loading history...
74
            [
75
                'event' => 'test',
76
                'method' => 'handle',
77
                'priority' => 10,
78
                'source' => 'interface'
79
            ]
80
        ]);
81
    }
82
83
    public function it_has_a_file_path()
84
    {
85
        $this->filePath()->shouldBe(__DIR__. '/Listener/ClassListener.php');
0 ignored issues
show
Bug introduced by
The method filePath() does not exist on spec\Slick\Event\Application\ListenerClassFileSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
        $this->/** @scrutinizer ignore-call */ 
86
               filePath()->shouldBe(__DIR__. '/Listener/ClassListener.php');
Loading history...
86
    }
87
88
    public function it_can_be_serialized(ContainerInterface $container)
89
    {
90
        $listener = new ClassListener();
91
        $container->get(ClassListener::class)->shouldBeCalled()->willReturn($listener);
92
        $serData = serialize($this->getWrappedObject());
93
        /** @var ListenerClassFile $unserialized */
94
        $unserialized = unserialize($serData);
95
        $unserialized->withContainer($container->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method getWrappedObject() does not exist on Psr\Container\ContainerInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
        $unserialized->withContainer($container->/** @scrutinizer ignore-call */ getWrappedObject());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
96
        if (!$unserialized->isListener()) {
97
            throw new FailedPredictionException("Error unserializing listener");
98
        }
99
100
        $listenerResult = $unserialized->resolveListeners()[0]['listener'];
101
        if ($listenerResult !== $listener) {
102
            throw new FailedPredictionException(
103
                "Error unserializing listener: couldn't retrieve the listener instance."
104
            );
105
        }
106
    }
107
}
108