1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Cubiche package. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Cubiche |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace Cubiche\Core\Bus\Tests\Units; |
11
|
|
|
|
12
|
|
|
use Cubiche\Core\Bus\Bus; |
13
|
|
|
use Cubiche\Core\Bus\Exception\InvalidMiddlewareException; |
14
|
|
|
use Cubiche\Core\Bus\Middlewares\Locking\LockingMiddleware; |
15
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\FooMessage; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* BusTests class. |
19
|
|
|
* |
20
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class BusTests extends TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Test create with invalid middleware. |
26
|
|
|
*/ |
27
|
|
|
public function testCreateWithInvalidMiddleware() |
28
|
|
|
{ |
29
|
|
|
$this |
30
|
|
|
->given($middleware = new LockingMiddleware()) |
31
|
|
|
->then() |
32
|
|
|
->exception(function () use ($middleware) { |
33
|
|
|
new Bus([$middleware, new \StdClass()]); |
|
|
|
|
34
|
|
|
}) |
35
|
|
|
->isInstanceOf(InvalidMiddlewareException::class) |
36
|
|
|
; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Test dispatch method. |
41
|
|
|
*/ |
42
|
|
|
public function testDispatch() |
43
|
|
|
{ |
44
|
|
|
$this |
45
|
|
|
->given($middleware = new LockingMiddleware()) |
46
|
|
|
->and($bus = new Bus([12 => $middleware])) |
47
|
|
|
->when($result = $bus->dispatch(new FooMessage())) |
48
|
|
|
->then() |
49
|
|
|
->variable($result) |
50
|
|
|
->isNull() |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Test addMiddlewareBefore method. |
56
|
|
|
*/ |
57
|
|
View Code Duplication |
public function testAddMiddlewareBefore() |
|
|
|
|
58
|
|
|
{ |
59
|
|
|
$this |
60
|
|
|
->given($middleware = new LockingMiddleware()) |
61
|
|
|
->and($bus = new Bus([12 => $middleware])) |
62
|
|
|
->when($result = $bus->addMiddlewareBefore($middleware, $middleware)) |
|
|
|
|
63
|
|
|
->then() |
64
|
|
|
->variable($result) |
65
|
|
|
->isNull() |
66
|
|
|
; |
67
|
|
|
|
68
|
|
|
$this |
69
|
|
|
->given($middleware = new LockingMiddleware()) |
70
|
|
|
->and($bus = new Bus()) |
71
|
|
|
->then() |
72
|
|
|
->exception(function () use ($bus, $middleware) { |
73
|
|
|
$bus->addMiddlewareBefore($middleware, $middleware); |
74
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Test addMiddlewareAfter method. |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function testAddMiddlewareAfter() |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$this |
84
|
|
|
->given($middleware = new LockingMiddleware()) |
85
|
|
|
->and($bus = new Bus([12 => $middleware])) |
86
|
|
|
->when($result = $bus->addMiddlewareAfter($middleware, $middleware)) |
|
|
|
|
87
|
|
|
->then() |
88
|
|
|
->variable($result) |
89
|
|
|
->isNull() |
90
|
|
|
; |
91
|
|
|
|
92
|
|
|
$this |
93
|
|
|
->given($middleware = new LockingMiddleware()) |
94
|
|
|
->and($bus = new Bus()) |
95
|
|
|
->then() |
96
|
|
|
->exception(function () use ($bus, $middleware) { |
97
|
|
|
$bus->addMiddlewareAfter($middleware, $middleware); |
98
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
99
|
|
|
; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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: