1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the AMFConsoleBundle. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tests\Validator\Constraints; |
11
|
|
|
|
12
|
|
|
use AMF\ConsoleBundle\Validator\Constraints\AllowedCommandValidator; |
13
|
|
|
use AMF\ConsoleBundle\Validator\Constraints\AllowedCommand; |
14
|
|
|
use Symfony\Component\Validator\Exception\UnexpectedTypeException; |
15
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
16
|
|
|
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface; |
17
|
|
|
use Symfony\Component\Validator\Constraints\Blank; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Test case for AllowedCommandValidator |
21
|
|
|
* |
22
|
|
|
* @author Amine Fattouch <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class AllowedCommandValidatorTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Phake_IMock |
29
|
|
|
*/ |
30
|
|
|
private $context; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var \Phake_IMock |
34
|
|
|
*/ |
35
|
|
|
private $contextViolation; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \Phake_IMock |
39
|
|
|
*/ |
40
|
|
|
private $allowedCommandValidator; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Configures current tests. |
44
|
|
|
*/ |
45
|
|
|
public function setUp() |
46
|
|
|
{ |
47
|
|
|
$this->context = \Phake::mock(ExecutionContextInterface::class); |
48
|
|
|
$this->contextViolation = \Phake::mock(ConstraintViolationBuilderInterface::class); |
49
|
|
|
$this->allowedCommandValidator = \Phake::partialMock(AllowedCommandValidator::class, ['amf']); |
50
|
|
|
|
51
|
|
|
$this->allowedCommandValidator->initialize($this->context); |
|
|
|
|
52
|
|
|
\Phake::when($this->context)->buildViolation($this->anything())->thenReturn($this->contextViolation); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @test |
57
|
|
|
*/ |
58
|
|
|
public function shouldThrowAnExceptionIfConstraintTypeIsWrong() |
59
|
|
|
{ |
60
|
|
|
$this->expectException(UnexpectedTypeException::class); |
61
|
|
|
|
62
|
|
|
$this->allowedCommandValidator->validate('test', new Blank()); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @test |
67
|
|
|
*/ |
68
|
|
|
public function shouldBuildViolationIfCommandIsNotAllowed() |
69
|
|
|
{ |
70
|
|
|
$this->allowedCommandValidator->validate('test', new AllowedCommand()); |
|
|
|
|
71
|
|
|
|
72
|
|
|
\Phake::verify($this->context)->buildViolation($this->anything()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @test |
77
|
|
|
*/ |
78
|
|
|
public function shouldNotBuildViolationIfCommandIsAllowed() |
79
|
|
|
{ |
80
|
|
|
$this->allowedCommandValidator->validate('amf:test2', new AllowedCommand()); |
|
|
|
|
81
|
|
|
|
82
|
|
|
\Phake::verifyNoInteraction($this->context); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.