AllowedCommandValidatorTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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);
0 ignored issues
show
Bug introduced by
The method initialize() does not seem to exist on object<Phake_IMock>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method validate() does not seem to exist on object<Phake_IMock>.

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.

Loading history...
63
    }
64
65
    /**
66
     * @test
67
     */
68
    public function shouldBuildViolationIfCommandIsNotAllowed()
69
    {
70
        $this->allowedCommandValidator->validate('test', new AllowedCommand());
0 ignored issues
show
Bug introduced by
The method validate() does not seem to exist on object<Phake_IMock>.

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.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method validate() does not seem to exist on object<Phake_IMock>.

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.

Loading history...
81
82
        \Phake::verifyNoInteraction($this->context);
83
    }
84
}
85