Skip to content

Commit

Permalink
Merge pull request #5014 from dlubitz/90/feature/allow-fusion-cache-i…
Browse files Browse the repository at this point in the history
…n-behat

TASK: Allow to enable Fusion caching for Behat tests
  • Loading branch information
mhsdesign committed Apr 29, 2024
2 parents 6212841 + 23ebd0c commit 13c7f4b
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/FusionTrait.php
Expand Up @@ -28,6 +28,7 @@
use Neos\Neos\Domain\Service\RenderingModeService;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ServerRequestFactoryInterface;
use Neos\Fusion\Core\Cache\ContentCache;

/**
* @internal only for behat tests within the Neos.Neos package
Expand All @@ -47,6 +48,8 @@ trait FusionTrait

private ?\Throwable $lastRenderingException = null;

private $contentCacheEnabled = false;

/**
* @template T of object
* @param class-string<T> $className
Expand All @@ -63,6 +66,7 @@ public function setupFusionContext(): void
$this->fusionGlobalContext = [];
$this->fusionContext = [];
$this->fusionCode = null;
$this->contentCacheEnabled = false;
$this->renderingResult = null;
}

Expand Down Expand Up @@ -114,6 +118,14 @@ public function iHaveTheFollowingFusionSetup(PyStringNode $fusionCode): void
$this->fusionCode = $fusionCode->getRaw();
}

/**
* @When I have Fusion content cache enabled
*/
public function iHaveFusionContentCacheEnabled(): void
{
$this->contentCacheEnabled = true;
}

/**
* @When I execute the following Fusion code:
* @When I execute the following Fusion code on path :path:
Expand All @@ -131,6 +143,7 @@ public function iExecuteTheFollowingFusionCode(PyStringNode $fusionCode, string
$fusionGlobals = FusionGlobals::fromArray($this->fusionGlobalContext);

$fusionRuntime = (new RuntimeFactory())->createFromConfiguration($fusionAst, $fusionGlobals);
$fusionRuntime->setEnableContentCache($this->contentCacheEnabled);
$fusionRuntime->overrideExceptionHandler($this->getObject(ThrowingHandler::class));
$fusionRuntime->pushContextArray($this->fusionContext);
try {
Expand Down Expand Up @@ -192,4 +205,12 @@ public function throwExceptionIfLastRenderingLedToAnError(): void
}
}

/**
* @BeforeScenario
*/
public function clearFusionCaches()
{
$this->getObject(ContentCache::class)->flush();
}

}
66 changes: 66 additions & 0 deletions Neos.Neos/Tests/Behavior/Features/Fusion/ContentCache.feature
@@ -0,0 +1,66 @@
@flowEntities @contentrepository
Feature: Tests for Fusion ContentCache
Background:
Given I have Fusion content cache enabled
And I have the following Fusion setup:
"""fusion
include: resource://Neos.Fusion/Private/Fusion/Root.fusion
include: resource://Neos.Neos/Private/Fusion/Root.fusion
prototype(Neos.Neos:Test.ContentCache) < prototype(Neos.Fusion:Component) {
foo = ''
renderer = ${props.foo}
@cache {
mode = 'cached'
entryIdentifier {
test = 'test'
}
}
}
"""

Scenario: Render a cached prototype and check if rerendering doesn't happen on second try
When I execute the following Fusion code:
"""fusion
test = Neos.Neos:Test.ContentCache {
foo = 'some-cached-string'
}
"""
Then I expect the following Fusion rendering result:
"""
some-cached-string
"""
When I execute the following Fusion code:
"""fusion
test = Neos.Neos:Test.ContentCache {
foo = 'some-other-string'
}
"""
Then I expect the following Fusion rendering result:
"""
some-cached-string
"""


Scenario: Check if cached got flushed before running a new scenario and no leftover of last test is there
When I execute the following Fusion code:
"""fusion
test = Neos.Neos:Test.ContentCache {
foo = 'some-new-string'
}
"""
Then I expect the following Fusion rendering result:
"""
some-new-string
"""
When I execute the following Fusion code:
"""fusion
test = Neos.Neos:Test.ContentCache {
foo = 'totally-different-string'
}
"""
Then I expect the following Fusion rendering result:
"""
some-new-string
"""

0 comments on commit 13c7f4b

Please sign in to comment.