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
|
|
|
|