ScopeTest::testSetLeft()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
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\Twig\NodeVisitor;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Twig\NodeVisitor\Scope;
15
16
class ScopeTest extends TestCase
17
{
18
    public function testSetGet()
19
    {
20
        $scope = new Scope();
21
        $scope->set('a', 1);
22
23
        $this->assertTrue($scope->has('a'));
24
        $this->assertFalse($scope->has('b'));
25
26
        $this->assertEquals(1, $scope->get('a'));
27
        $this->assertEquals(2, $scope->get('b', 2));
28
        $this->assertNull($scope->get('b'));
29
    }
30
31
    public function testEnterLeave()
32
    {
33
        $scope = new Scope();
34
        $childScope = $scope->enter();
35
36
        $this->assertInstanceOf(Scope::class, $childScope);
37
        $this->assertNotSame($scope, $childScope);
38
39
        $parentScope = $childScope->leave();
40
        $this->assertInstanceOf(Scope::class, $parentScope);
41
        $this->assertSame($scope, $parentScope);
42
    }
43
44
    public function testSetLeft()
45
    {
46
        $scope = new Scope();
47
        $childScope = $scope->enter();
48
        $childScope->leave();
49
50
        $this->expectException(\LogicException::class);
51
        $this->expectExceptionMessage('Left scope is not mutable.');
52
53
        $childScope->set('a', 5);
54
    }
55
}
56