CallableEventListenerSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 Slick\Event\Application\CallableEventListener;
13
use PhpSpec\ObjectBehavior;
14
use Slick\Event\Event;
15
16
/**
17
 * CallableEventListenerSpec specs
18
 *
19
 * @package spec\Slick\Event\Application
20
 */
21
class CallableEventListenerSpec extends ObjectBehavior
22
{
23
    private bool $called = false;
24
    public function let()
25
    {
26
        $callable = function (object $event) {
27
            $this->called = true;
28
            return $event;
29
        };
30
        $this->beConstructedWith($callable);
31
    }
32
33
    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...
34
    {
35
        $this->shouldHaveType(CallableEventListener::class);
36
    }
37
38
    function it_call_callable_on_execute(Event $event)
39
    {
40
        $this->handle($event)->shouldBe($event);
0 ignored issues
show
Bug introduced by
The method handle() does not exist on spec\Slick\Event\Applica...llableEventListenerSpec. 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

40
        $this->/** @scrutinizer ignore-call */ 
41
               handle($event)->shouldBe($event);
Loading history...
41
        if (!$this->called) {
42
            throw new \Exception("Callable listener not called");
43
        }
44
    }
45
}
46