ExpressionDecoratorTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\ExpressionLanguage;
12
13
use PHPUnit\Framework\TestCase;
14
use Symfony\Component\ExpressionLanguage\Expression;
15
use Yarhon\RouteGuardBundle\ExpressionLanguage\ExpressionDecorator;
16
use Yarhon\RouteGuardBundle\Exception\InvalidArgumentException;
17
18
/**
19
 * @group requires-expression-language
20
 *
21
 * @author Yaroslav Honcharuk <[email protected]>
22
 */
23
class ExpressionDecoratorTest extends TestCase
24
{
25
    private $expression;
26
27
    public function setUp()
28
    {
29
        $this->expression = $this->createMock(Expression::class);
30
    }
31
32
    public function testConstruct()
33
    {
34
        $expressionDecorator = new ExpressionDecorator($this->expression, ['foo']);
35
36
        $this->assertSame($this->expression, $expressionDecorator->getExpression());
37
        $this->assertSame(['foo'], $expressionDecorator->getVariableNames());
38
    }
39
40
    public function testVariables()
41
    {
42
        $expressionDecorator = new ExpressionDecorator($this->expression, ['foo']);
43
44
        $expressionDecorator->setVariables(['foo' => 1]);
45
46
        $this->assertSame(['foo' => 1], $expressionDecorator->getVariables());
47
    }
48
49
    public function testVariablesMissedException()
50
    {
51
        $expressionDecorator = new ExpressionDecorator($this->expression, ['foo', 'bar']);
52
53
        $this->expectException(InvalidArgumentException::class);
54
        $this->expectExceptionMessage('Missed variables: "foo", "bar".');
55
56
        $expressionDecorator->setVariables([]);
57
    }
58
59
    public function testVariablesUnknownException()
60
    {
61
        $expressionDecorator = new ExpressionDecorator($this->expression, ['foo']);
62
63
        $this->expectException(InvalidArgumentException::class);
64
        $this->expectExceptionMessage('Unknown variables: "foo1", "bar".');
65
66
        $expressionDecorator->setVariables(['foo' => 1, 'foo1' => 2, 'bar' => 3]);
67
    }
68
}
69