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
|
|
|
namespace Cubiche\Core\Bus\Tests\Units\Middlewares\Locking; |
12
|
|
|
|
13
|
|
|
use Cubiche\Core\Bus\Middlewares\Locking\LockingMiddleware; |
14
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Event\LoginUserEvent; |
15
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Event\TriggerEventOnListener; |
16
|
|
|
use Cubiche\Core\Bus\Tests\Units\TestCase; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* LockingMiddleware class. |
20
|
|
|
* |
21
|
|
|
* Generated by TestGenerator on 2016-04-07 at 15:40:41. |
22
|
|
|
*/ |
23
|
|
|
class LockingMiddlewareTests extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Test handle method. |
27
|
|
|
*/ |
28
|
|
|
public function testHandleEvent() |
29
|
|
|
{ |
30
|
|
|
$this |
31
|
|
|
->given($middleware = new LockingMiddleware()) |
32
|
|
|
->and($event = new LoginUserEvent('[email protected]')) |
33
|
|
|
->and($callable = function (LoginUserEvent $event) { |
34
|
|
|
$event->setEmail('[email protected]'); |
35
|
|
|
}) |
36
|
|
|
->when($middleware->handle($event, $callable)) |
37
|
|
|
->then() |
38
|
|
|
->string($event->email()) |
39
|
|
|
->isEqualTo('[email protected]') |
40
|
|
|
; |
41
|
|
|
|
42
|
|
|
$this |
43
|
|
|
->given($middleware = new LockingMiddleware()) |
44
|
|
|
->and($event = new LoginUserEvent('[email protected]')) |
45
|
|
|
->and($callable = function (LoginUserEvent $event) { |
46
|
|
|
$event->setEmail('[email protected]'); |
47
|
|
|
|
48
|
|
|
throw new \InvalidArgumentException(); |
49
|
|
|
}) |
50
|
|
|
->then() |
51
|
|
|
->exception(function () use ($middleware, $event, $callable) { |
52
|
|
|
$middleware->handle($event, $callable); |
53
|
|
|
}) |
54
|
|
|
->isInstanceOf(\InvalidArgumentException::class) |
55
|
|
|
; |
56
|
|
|
|
57
|
|
|
$this |
58
|
|
|
->given($middleware = new LockingMiddleware()) |
59
|
|
|
->and($callable = function (LoginUserEvent $event) { |
60
|
|
|
$event->setEmail(md5($event->email())); |
61
|
|
|
}) |
62
|
|
|
->and($listener = new TriggerEventOnListener($middleware, $callable)) |
63
|
|
|
->and($event = new LoginUserEvent('[email protected]')) |
64
|
|
|
->when($middleware->handle($event, function ($event) use ($listener) { |
65
|
|
|
$listener->onLogin($event); |
66
|
|
|
})) |
67
|
|
|
->then() |
68
|
|
|
->string($event->email()) |
69
|
|
|
->isEqualTo(md5(sha1('[email protected]'))) |
70
|
|
|
; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|