ChainResolverTests::testResolve()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 17
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\Resolver\HandlerMethodName;
13
14
use Cubiche\Core\Bus\Exception\NotFoundException;
15
use Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName\ChainResolver;
16
use Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName\DefaultResolver;
17
use Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName\MethodWithShortObjectNameAndSuffixResolver;
18
use Cubiche\Core\Bus\Middlewares\Handler\Resolver\HandlerMethodName\MethodWithShortObjectNameResolver;
19
use Cubiche\Core\Bus\Tests\Fixtures\Message\LoginUserMessage;
20
use Cubiche\Core\Bus\Tests\Fixtures\Message\LogoutUserMessage;
21
use Cubiche\Core\Bus\Tests\Fixtures\InvalidHandlerMethodNameResolver;
22
use Cubiche\Core\Bus\Tests\Units\TestCase;
23
24
/**
25
 * ChainResolver class.
26
 *
27
 * Generated by TestGenerator on 2016-04-07 at 15:40:41.
28
 */
29
class ChainResolverTests extends TestCase
30
{
31
    /**
32
     * Test Resolve method.
33
     */
34
    public function testResolve()
35
    {
36
        $this
37
            ->given($resolver1 = new InvalidHandlerMethodNameResolver())
38
            ->and($resolver2 = new MethodWithShortObjectNameAndSuffixResolver('Listener'))
39
            ->and($resolver3 = new MethodWithShortObjectNameResolver('Message'))
40
            ->and($resolver4 = new DefaultResolver())
41
            ->and($resolver = new ChainResolver([$resolver1, $resolver2, $resolver3, $resolver4]))
42
            ->when($result = $resolver->resolve(LoginUserMessage::class))
43
            ->then()
44
                ->string($result)
45
                    ->isEqualTo('loginUser')
46
        ;
47
48
        $this
49
            ->given($resolver = new ChainResolver([]))
50
            ->then()
51
                ->exception(function () use ($resolver) {
52
                    $resolver->resolve(new LogoutUserMessage('[email protected]'));
0 ignored issues
show
Documentation introduced by
new \Cubiche\Core\Bus\Te...age('[email protected]') is of type object<Cubiche\Core\Bus\...sage\LogoutUserMessage>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
                })
54
                ->isInstanceOf(NotFoundException::class)
55
        ;
56
    }
57
}
58