DispatchableTest::test_dispatchUnless()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 5
c 2
b 1
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\EventDispatcher\Tests\Events;
4
5
use ByTIC\EventDispatcher\Tests\AbstractTest;
6
use ByTIC\EventDispatcher\Tests\Fixtures\Events\Event;
7
use ByTIC\EventDispatcher\Tests\Fixtures\Events\ExtendedEvent;
8
9
/**
10
 * Class DispatchableTest
11
 * @package ByTIC\EventDispatcher\Tests\Events
12
 */
13
class DispatchableTest extends AbstractTest
14
{
15
    public function test_dispatch()
16
    {
17
        $dispatcher = $this->mockDispatcherInContainer();
18
        $dispatcher->shouldReceive('dispatch')->twice()->andReturnArg(0);
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on ByTIC\EventDispatcher\Dispatcher\EventDispatcher. ( Ignorable by Annotation )

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

18
        $dispatcher->/** @scrutinizer ignore-call */ 
19
                     shouldReceive('dispatch')->twice()->andReturnArg(0);

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...
19
20
        $event = Event::dispatch();
21
        self::assertInstanceOf(Event::class, $event);
22
23
        $event = ExtendedEvent::dispatch();
24
        self::assertInstanceOf(ExtendedEvent::class, $event);
25
    }
26
27
    public function test_dispatchIf()
28
    {
29
        $dispatcher = $this->mockDispatcherInContainer();
30
        $dispatcher->shouldReceive('dispatch')->once()->andReturnArg(0);
31
32
        self::assertSame(null, Event::dispatchIf(false));
33
34
        $event = Event::dispatchIf(true);
35
        self::assertInstanceOf(Event::class, $event);
36
    }
37
38
    public function test_dispatchUnless()
39
    {
40
        $dispatcher = $this->mockDispatcherInContainer();
41
        $dispatcher->shouldReceive('dispatch')->once()->andReturnArg(0);
42
43
44
        self::assertSame(null, Event::dispatchUnless(true));
45
46
        $event = Event::dispatchUnless(false);
47
        self::assertInstanceOf(Event::class, $event);
48
    }
49
}
50