Passed
Pull Request — master (#653)
by Aleksei
07:43
created

ConditionalTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 35
dl 0
loc 83
rs 10
c 0
b 0
f 0
wmc 8
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Stempler\Directive;
13
14
use Spiral\Stempler\Directive\ConditionalDirective;
15
16
class ConditionalTest extends BaseTest
17
{
18
    protected const DIRECTIVES = [
19
        ConditionalDirective::class
20
    ];
21
22
    public function testIfEndif(): void
23
    {
24
        $doc = $this->parse('@if(true) ok @endif');
25
26
        $this->assertSame(
27
            '<?php if(true): ?> ok <?php endif; ?>',
28
            $this->compile($doc)
29
        );
30
    }
31
32
    public function testIfElseEndif(): void
33
    {
34
        $doc = $this->parse('@if(true) ok @else bad @endif');
35
36
        $this->assertSame(
37
            '<?php if(true): ?> ok <?php else: ?> bad <?php endif; ?>',
38
            $this->compile($doc)
39
        );
40
    }
41
42
    public function testIfElseifElseEndif(): void
43
    {
44
        $doc = $this->parse('@if(true) ok @elseif(true) other @else bad @endif');
45
46
        $this->assertSame(
47
            '<?php if(true): ?> ok <?php elseif(true): ?> other <?php else: ?> bad <?php endif; ?>',
48
            $this->compile($doc)
49
        );
50
    }
51
52
    public function testUnless(): void
53
    {
54
        $doc = $this->parse('@unless(false) ok @endunless');
55
56
        $this->assertSame(
57
            '<?php if(!(false)): ?> ok <?php endif; ?>',
58
            $this->compile($doc)
59
        );
60
    }
61
62
    public function testIsset(): void
63
    {
64
        $doc = $this->parse('@isset($var) ok @endisset');
65
66
        $this->assertSame(
67
            '<?php if(isset($var)): ?> ok <?php endif; ?>',
68
            $this->compile($doc)
69
        );
70
    }
71
72
    public function testEmpty(): void
73
    {
74
        $doc = $this->parse('@empty($var) ok @endempty');
75
76
        $this->assertSame(
77
            '<?php if(empty($var)): ?> ok <?php endif; ?>',
78
            $this->compile($doc)
79
        );
80
    }
81
82
    public function testSwitchCase(): void
83
    {
84
        $doc = $this->parse('@switch(1) @case(1) 1 @endswitch');
85
86
        $this->assertSame(
87
            '<?php switch(1): case (1): ?> 1 <?php endswitch; ?>',
88
            $this->compile($doc)
89
        );
90
    }
91
92
    public function testSwitchCaseDefaultBreak(): void
93
    {
94
        $doc = $this->parse('@switch($var) @case(1) 1 @break @default default @endswitch');
95
96
        $this->assertSame(
97
            '<?php switch($var): case (1): ?> 1 <?php break; ?> <?php default: ?> default <?php endswitch; ?>',
98
            $this->compile($doc)
99
        );
100
    }
101
}
102