Passed
Push — master ( 72c793...7f699f )
by Kirill
03:22
created

NativeTest::testRenderBufferException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.9666
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\Views;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Core\Container;
16
use Spiral\Views\Engine\Native\NativeEngine;
17
use Spiral\Views\Exception\EngineException;
18
use Spiral\Views\Exception\RenderException;
19
use Spiral\Views\ViewContext;
20
use Spiral\Views\ViewLoader;
21
22
class NativeTest extends TestCase
23
{
24
    public function testGet(): void
25
    {
26
        $loader = new ViewLoader([
27
            'default' => __DIR__ . '/fixtures/default',
28
            'other'   => __DIR__ . '/fixtures/other',
29
        ]);
30
31
        $loader = $loader->withExtension('php');
32
33
        $engine = new NativeEngine(new Container());
34
        $engine = $engine->withLoader($loader);
35
36
        $engine->reset('other:view', new ViewContext());
37
        $engine->compile('other:view', new ViewContext());
38
        $view = $engine->get('other:view', $ctx = new ViewContext());
39
40
        $this->assertSame('other world', $view->render([]));
41
    }
42
43
    public function testGetNoLoader(): void
44
    {
45
        $this->expectException(EngineException::class);
46
47
        $engine = new NativeEngine(new Container());
48
        $engine->get('other:view', new ViewContext());
49
    }
50
51
    public function testRenderWithValue(): void
52
    {
53
        $loader = new ViewLoader([
54
            'default' => __DIR__ . '/fixtures/default',
55
            'other'   => __DIR__ . '/fixtures/other',
56
57
        ]);
58
59
        $loader = $loader->withExtension('php');
60
61
        $engine = new NativeEngine(new Container());
62
        $engine = $engine->withLoader($loader);
63
64
        $view = $engine->get('other:var', $ctx = new ViewContext());
65
        $this->assertSame('hello', $view->render(['value' => 'hello']));
66
    }
67
68
    public function testRenderException(): void
69
    {
70
        $this->expectException(RenderException::class);
71
72
        $loader = new ViewLoader([
73
            'default' => __DIR__ . '/fixtures/default',
74
            'other'   => __DIR__ . '/fixtures/other',
75
76
        ]);
77
78
        $loader = $loader->withExtension('php');
79
80
        $engine = new NativeEngine(new Container());
81
        $engine = $engine->withLoader($loader);
82
83
        $view = $engine->get('other:var', $ctx = new ViewContext());
84
85
        $view->render([]);
86
    }
87
88
    public function testRenderBufferWithValue(): void
89
    {
90
        $loader = new ViewLoader([
91
            'default' => __DIR__ . '/fixtures/default',
92
            'other'   => __DIR__ . '/fixtures/other',
93
94
        ]);
95
96
        $loader = $loader->withExtension('php');
97
98
        $engine = new NativeEngine(new Container());
99
        $engine = $engine->withLoader($loader);
100
101
        $view = $engine->get('other:buf', $ctx = new ViewContext());
102
        $this->assertSame('', $view->render(['value' => 'hello']));
103
    }
104
105
    public function testRenderBufferException(): void
106
    {
107
        $this->expectException(RenderException::class);
108
109
        $loader = new ViewLoader([
110
            'default' => __DIR__ . '/fixtures/default',
111
            'other'   => __DIR__ . '/fixtures/other',
112
113
        ]);
114
115
        $loader = $loader->withExtension('php');
116
117
        $engine = new NativeEngine(new Container());
118
        $engine = $engine->withLoader($loader);
119
120
        $view = $engine->get('other:buf', $ctx = new ViewContext());
121
122
        $view->render([]);
123
    }
124
}
125