|
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\Validator; |
|
13
|
|
|
|
|
14
|
|
|
use Cubiche\Core\Bus\Middlewares\Validator\ValidatorMiddleware; |
|
15
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Message\LoginUserMessage; |
|
16
|
|
|
use Cubiche\Core\Bus\Tests\Fixtures\Message\LogoutUserMessage; |
|
17
|
|
|
use Cubiche\Core\Bus\Tests\Units\TestCase; |
|
18
|
|
|
use Cubiche\Core\Validator\Exception\ValidationException; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* ValidatorMiddleware class. |
|
22
|
|
|
* |
|
23
|
|
|
* Generated by TestGenerator on 2016-04-11 at 15:18:25. |
|
24
|
|
|
*/ |
|
25
|
|
|
class ValidatorMiddlewareTests extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Test handle method. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testHandle() |
|
31
|
|
|
{ |
|
32
|
|
|
$this |
|
33
|
|
|
->given($middleware = new ValidatorMiddleware()) |
|
34
|
|
|
->and($command = new LoginUserMessage('[email protected]', 'plainpassword')) |
|
|
|
|
|
|
35
|
|
|
->and($callable = function (LoginUserMessage $command) { |
|
36
|
|
|
$command->setEmail('[email protected]'); |
|
37
|
|
|
}) |
|
38
|
|
|
->when($middleware->handle($command, $callable)) |
|
39
|
|
|
->then() |
|
40
|
|
|
->string($command->email()) |
|
41
|
|
|
->isEqualTo('[email protected]') |
|
42
|
|
|
; |
|
43
|
|
|
|
|
44
|
|
|
$this |
|
45
|
|
|
->given($middleware = new ValidatorMiddleware()) |
|
46
|
|
|
->and($command = new LoginUserMessage('invalid.email.com', 'plainpassword')) |
|
|
|
|
|
|
47
|
|
|
->and($callable = function () { |
|
48
|
|
|
}) |
|
49
|
|
|
->then() |
|
50
|
|
|
->exception(function () use ($middleware, $command, $callable) { |
|
51
|
|
|
$middleware->handle($command, $callable); |
|
52
|
|
|
})->isInstanceOf(ValidationException::class) |
|
53
|
|
|
; |
|
54
|
|
|
|
|
55
|
|
|
$this |
|
56
|
|
|
->given($middleware = new ValidatorMiddleware()) |
|
57
|
|
|
->and($command = new LogoutUserMessage('invalid.email.com')) |
|
58
|
|
|
->and($callable = function (LogoutUserMessage $command) { |
|
59
|
|
|
$command->setEmail('[email protected]'); |
|
60
|
|
|
}) |
|
61
|
|
|
->when($middleware->handle($command, $callable)) |
|
62
|
|
|
->then() |
|
63
|
|
|
->string($command->email()) |
|
64
|
|
|
->isEqualTo('[email protected]') |
|
65
|
|
|
; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.