Completed
Push — master ( 6730ca...33ba9e )
by Ivannis Suárez
07:46
created

LocatorTestCase::testAddHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Cubiche\Core\Bus\Tests\Units\Middlewares\Handler\Locator;
13
14
use Cubiche\Core\Bus\Exception\NotFoundException;
15
use Cubiche\Core\Bus\Middlewares\Handler\Locator\LocatorInterface;
16
use Cubiche\Core\Bus\Tests\Fixtures\Message\LoginUserMessage;
17
use Cubiche\Core\Bus\Tests\Fixtures\Message\LoginUserMessageListener;
18
use Cubiche\Core\Bus\Tests\Units\TestCase;
19
20
/**
21
 * LocatorTestCase class.
22
 *
23
 * Generated by TestGenerator on 2016-04-07 at 15:40:41.
24
 */
25
abstract class LocatorTestCase extends TestCase
26
{
27
    /**
28
     * @return LocatorInterface
29
     */
30
    abstract protected function createLocator();
31
32
    /**
33
     * Test create.
34
     */
35
    public function testCreate()
36
    {
37
        $this
38
            ->given($locator = $this->createLocator())
39
            ->then()
40
                ->object($locator)
41
                    ->isInstanceOf(LocatorInterface::class)
42
        ;
43
    }
44
45
    /**
46
     * Test addHandler.
47
     */
48
    public function testAddHandler()
49
    {
50
        $this
51
            ->given($locator = $this->createLocator())
52
            ->and($handler = new LoginUserMessageListener())
53
            ->then()
54
                ->exception(function () use ($locator, $handler) {
55
                    $locator->addHandler(255, $handler);
56
                })
57
                ->isInstanceOf(\InvalidArgumentException::class)
58
        ;
59
    }
60
61
    /**
62
     * Test Locate method.
63
     */
64
    public function testLocate()
65
    {
66
        $this
67
            ->given($locator = $this->createLocator())
68
            ->then()
69
                ->exception(function () use ($locator) {
70
                    $locator->locate(LoginUserMessage::class);
71
                })
72
                ->isInstanceOf(NotFoundException::class)
73
        ;
74
75
        $this
76
            ->given($handler = new LoginUserMessageListener())
77
            ->and($locator = $this->createLocator())
78
            ->when($locator->addHandler(LoginUserMessage::class, $handler))
79
            ->then()
80
                ->object($locator->locate(LoginUserMessage::class))
81
                    ->isEqualTo($handler)
82
                ->and()
83
                ->exception(function () use ($locator) {
84
                    $locator->locate('Foo');
85
                })
86
                ->isInstanceOf(NotFoundException::class)
87
        ;
88
    }
89
}
90