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\Validator; |
12
|
|
|
|
13
|
|
|
use Cubiche\Core\Bus\Middlewares\Validator\ValidatorMiddleware; |
14
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Command\LoginUserCommand; |
15
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Command\LogoutUserCommand; |
16
|
|
|
use Cubiche\Core\Bus\Tests\Units\TestCase; |
17
|
|
|
use Cubiche\Core\Validator\Exception\ValidationException; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* ValidatorMiddleware class. |
21
|
|
|
* |
22
|
|
|
* Generated by TestGenerator on 2016-04-11 at 15:18:25. |
23
|
|
|
*/ |
24
|
|
|
class ValidatorMiddlewareTests extends TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Test handle method. |
28
|
|
|
*/ |
29
|
|
|
public function testHandle() |
30
|
|
|
{ |
31
|
|
|
$this |
32
|
|
|
->given($middleware = new ValidatorMiddleware()) |
33
|
|
|
->and($command = new LoginUserCommand('[email protected]', 'plainpassword')) |
34
|
|
|
->and($callable = function (LoginUserCommand $command) { |
35
|
|
|
$command->setEmail('[email protected]'); |
36
|
|
|
}) |
37
|
|
|
->when($middleware->handle($command, $callable)) |
38
|
|
|
->then() |
39
|
|
|
->string($command->email()) |
40
|
|
|
->isEqualTo('[email protected]') |
41
|
|
|
; |
42
|
|
|
|
43
|
|
|
$this |
44
|
|
|
->given($middleware = new ValidatorMiddleware()) |
45
|
|
|
->and($command = new LoginUserCommand('invalid.email.com', 'plainpassword')) |
46
|
|
|
->and($callable = function () { |
47
|
|
|
}) |
48
|
|
|
->then() |
49
|
|
|
->exception(function () use ($middleware, $command, $callable) { |
50
|
|
|
$middleware->handle($command, $callable); |
51
|
|
|
})->isInstanceOf(ValidationException::class) |
52
|
|
|
; |
53
|
|
|
|
54
|
|
|
$this |
55
|
|
|
->given($middleware = new ValidatorMiddleware()) |
56
|
|
|
->and($command = new LogoutUserCommand('invalid.email.com')) |
57
|
|
|
->and($callable = function (LogoutUserCommand $command) { |
58
|
|
|
$command->setEmail('[email protected]'); |
59
|
|
|
}) |
60
|
|
|
->when($middleware->handle($command, $callable)) |
61
|
|
|
->then() |
62
|
|
|
->string($command->email()) |
63
|
|
|
->isEqualTo('[email protected]') |
64
|
|
|
; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|