Passed
Push — master ( e140d0...d9458c )
by Gabriel
12:38
created

DispatchableTest::test_dispatchIf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
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);
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
}