-
-
Notifications
You must be signed in to change notification settings - Fork 218
/
TestingViewForFusionRuntime.php
67 lines (57 loc) · 1.69 KB
/
TestingViewForFusionRuntime.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
namespace Neos\Fusion\Tests\Functional\FusionObjects;
use Neos\Fusion\Core\Runtime;
use Neos\Fusion\Exception\RuntimeException;
/**
* TODO THIS IS HACKY AS WE CREATE A SHALLOW ABSTRACTION FOR TESTING
*
* We do that as the FusionView (rightfully) doesn't return mixed anymore - but we test arbitrary data.
* {@see https://github.com/neos/neos-development-collection/pull/4856}
*
* We could instead also rewrite all tests to use the Runtime natively.
* But that would be a lot of effort and diff for nothing.
*
* Instead we want to refactor our fusion tests to behat at some point.
*
* Thus the (temporary) hack / abstraction.
*
* @deprecated todo rewrite everything as behat test :D
*/
class TestingViewForFusionRuntime
{
private string $fusionPath;
public function __construct(
private readonly Runtime $runtime
) {
}
public function setFusionPath(string $fusionPath)
{
$this->fusionPath = $fusionPath;
}
public function assign($key, $value)
{
$this->runtime->pushContext($key, $value);
}
public function setOption($key, $value)
{
match ($key) {
'enableContentCache' => $this->runtime->setEnableContentCache($value),
'debugMode' => $this->runtime->setDebugMode($value)
};
}
public function assignMultiple(array $values)
{
foreach ($values as $key => $value) {
$this->runtime->pushContext($key, $value);
}
}
public function render()
{
try {
return $this->runtime->render($this->fusionPath);
} catch (RuntimeException $e) {
throw $e->getWrappedException();
}
}
}