-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Introduce
TestingViewForFusionRuntime
for testing instead of …
…using a hacky anonymous class
- Loading branch information
Showing
3 changed files
with
73 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Neos.Fusion/Tests/Functional/FusionObjects/TestingViewForFusionRuntime.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters