Skip to content

Commit 5847af3

Browse files
authored
Fix failing tests (#32)
* Add necessary TypoScript Configuration The tests use `f:format.html` ViewHelper. This will call the `ContentObjectRenderer::parseFunc`. The default is to use `lib.parseFunc_RTE` as a reference. But this didn't exist within our test setup, leading to errors. We now ensure this path provides some configuration to pass the test. * Follow PHPUnit naming schema for Test Cases Our abstract TestCase wasn't named as one, leading to a PHPUnit warning. We therefore adjust the naming to follow the convention and prevent any warning. * Ensure Database cache backend is used As our tests use the database table to verify proper cache handling. The testing framework replaced the defaults with `NullBackend` for performance reasons. * Solve PHPUnit Deprecation DataProvider need to be static. * Fix none working DataHandler tests Pass necessary arguments to calls. Migrate from unnecessary prophecy to native PHPUnit API.
1 parent 524b6bd commit 5847af3

7 files changed

Lines changed: 52 additions & 31 deletions

File tree

Tests/Functional/Caching/FlushViaDataHandlerChangesTest.php

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
use Prophecy\PhpUnit\ProphecyTrait;
2828
use Sinso\Variables\Hooks\DataHandler;
2929
use TYPO3\CMS\Core\Cache\CacheManager;
30+
use TYPO3\CMS\Core\Database\ConnectionPool;
31+
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3DataHandler;
3032
use TYPO3\CMS\Core\Utility\GeneralUtility;
3133
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
3234

@@ -35,36 +37,26 @@
3537
*/
3638
class FlushViaDataHandlerChangesTest extends FunctionalTestCase
3739
{
38-
use ProphecyTrait;
39-
40-
public function testCanBeCreated(): void
41-
{
42-
$subject = new DataHandler();
43-
44-
self::assertInstanceOf(
45-
DataHandler::class,
46-
$subject
47-
);
48-
}
49-
5040
/**
5141
* @dataProvider possibleNoneTriggeringParams
5242
*/
5343
public function testDoesNotInteractWithCacheManagerOnUnkownData(array $params): void
5444
{
55-
$cacheManager = $this->prophesize(CacheManager::class);
56-
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal());
57-
58-
$subject = new DataHandler();
59-
$subject->clearCachePostProc($params);
60-
61-
$cacheManager->flushCachesInGroupByTag('pages', Argument::type('array'))->shouldNotBeCalled();
45+
$connectionPool = self::createMock(ConnectionPool::class);
46+
$cacheManager = self::createMock(CacheManager::class);
47+
$cacheManager
48+
->expects(self::never())
49+
->method('flushCachesInGroupByTag')
50+
;
51+
52+
$subject = new DataHandler($connectionPool, $cacheManager);
53+
$subject->clearCachePostProc($params, self::createStub(Typo3DataHandler::class));
6254
}
6355

6456
/**
6557
* @return Generator<string,array{params:array}|array{params:array<string,string>}>
6658
*/
67-
public function possibleNoneTriggeringParams(): \Generator
59+
public static function possibleNoneTriggeringParams(): \Generator
6860
{
6961
yield 'no table given' => [
7062
'params' => [],
@@ -85,16 +77,28 @@ public function possibleNoneTriggeringParams(): \Generator
8577

8678
public function testFlushCachesByGroupForMarker(): void
8779
{
88-
$cacheManager = $this->prophesize(CacheManager::class);
89-
GeneralUtility::setSingletonInstance(CacheManager::class, $cacheManager->reveal());
80+
$connectionPool = self::createMock(ConnectionPool::class);
81+
$cacheManager = self::createMock(CacheManager::class);
82+
$cacheManager
83+
->expects(self::once())
84+
->method('flushCachesInGroupByTag')
85+
->with('pages', $this->stringStartsWith('tx_variables_key_hash_'))
86+
;
87+
88+
$dataHandler = self::createStub(Typo3DataHandler::class);
89+
$dataHandler->datamap = [
90+
'tx_variables_marker' => [
91+
1 => [
92+
'marker' => 'TEST',
93+
],
94+
],
95+
];
9096

91-
$subject = new DataHandler();
97+
$subject = new DataHandler($connectionPool, $cacheManager);
9298
$subject->clearCachePostProc([
9399
'table' => 'tx_variables_marker',
94100
'uid' => '1',
95101
'marker' => 'TEST'
96-
]);
97-
98-
$cacheManager->flushCachesInGroupByTag('pages', 'tx_variables_key_hash_033bd94b1168d7e4f0d644c3c95e35bf')->shouldBeCalledOnce();
102+
], $dataHandler);
99103
}
100104
}

Tests/Functional/Fixtures/Frontend/Rendering.typoscript

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ tt_content.template = TEXT
66
tt_content.template.value = <p>{data.bodytext -> f:format.html()}</p>
77

88
plugin.tx_variables.persistence.storagePid = 4
9+
10+
lib.parseFunc_RTE {
11+
htmlSanitize = 1
12+
}

Tests/Functional/Frontend/AbstractProcessesMarkersTest.php renamed to Tests/Functional/Frontend/AbstractProcessesMarkersTestCase.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
namespace Sinso\Variables\Tests\Functional\Frontend;
2525

26+
use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
27+
use TYPO3\CMS\Core\Utility\ArrayUtility;
2628
use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
2729
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
2830

29-
abstract class AbstractProcessesMarkersTest extends FunctionalTestCase
31+
abstract class AbstractProcessesMarkersTestCase extends FunctionalTestCase
3032
{
3133
protected array $testExtensionsToLoad = [
3234
'typo3conf/ext/variables',
@@ -38,6 +40,18 @@ abstract class AbstractProcessesMarkersTest extends FunctionalTestCase
3840

3941
protected function setUp(): void
4042
{
43+
ArrayUtility::mergeRecursiveWithOverrule($this->configurationToUseInTestInstance, [
44+
'SYS' => [
45+
'caching' => [
46+
'cacheConfigurations' => [
47+
'pages' => [
48+
'backend' => Typo3DatabaseBackend::class,
49+
],
50+
],
51+
],
52+
],
53+
]);
54+
4155
parent::setUp();
4256

4357
$this->importDataSet('EXT:variables/Tests/Functional/Fixtures/Frontend/Content.xml');

Tests/Functional/Frontend/BreaksOnInvalidHookTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* @covers \Sinso\Variables\Service\VariablesService
3030
*/
31-
class BreaksOnInvalidHookTest extends AbstractProcessesMarkersTest
31+
class BreaksOnInvalidHookTest extends AbstractProcessesMarkersTestCase
3232
{
3333
protected array $configurationToUseInTestInstance = [
3434
'EXTCONF' => [

Tests/Functional/Frontend/ProcessesMarkersHookTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/**
2929
* @covers \Sinso\Variables\Hooks\ContentProcessor
3030
*/
31-
class ProcessesMarkersHookTest extends AbstractProcessesMarkersTest
31+
class ProcessesMarkersHookTest extends AbstractProcessesMarkersTestCase
3232
{
3333
protected array $configurationToUseInTestInstance = [
3434
'EXTCONF' => [

Tests/Functional/Frontend/ProcessesMarkersTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* @covers \Sinso\Variables\Hooks\ContentProcessor
2828
*/
29-
class ProcessesMarkersTest extends AbstractProcessesMarkersTest
29+
class ProcessesMarkersTest extends AbstractProcessesMarkersTestCase
3030
{
3131
public function testNoMarkerAppliedAsNoneExist(): void
3232
{

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"require-dev": {
2222
"rector/rector": "^0.12.23",
2323
"typo3/testing-framework": "^7.0",
24-
"phpspec/prophecy-phpunit": "^2.0",
2524
"symplify/easy-coding-standard": "^12.3"
2625
},
2726
"extra": {

0 commit comments

Comments
 (0)