Skip to content

Commit 670294c

Browse files
committed
Fix test execution and phpstan errors
1 parent 478e402 commit 670294c

File tree

8 files changed

+39
-19
lines changed

8 files changed

+39
-19
lines changed

Classes/Cache/RemoteFileBackend.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use TYPO3\CMS\Core\Cache\Backend\TaggableBackendInterface;
1111
use TYPO3\CMS\Core\Cache\Backend\TransientBackendInterface;
1212
use TYPO3\CMS\Core\Cache\Exception\InvalidDataException;
13+
use TYPO3\CMS\Core\Information\Typo3Version;
1314
use TYPO3\CMS\Core\Resource\ResourceFactory;
1415
use TYPO3\CMS\Core\Utility\GeneralUtility;
1516
use TYPO3\CMS\Core\Utility\PathUtility;
@@ -56,7 +57,7 @@ public function setHashLength(int $hashLength): void
5657
* Saves data in the cache.
5758
*
5859
* @param string $entryIdentifier An identifier for this specific cache entry
59-
* @param string $data The data to be stored
60+
* @param string|mixed $data The data to be stored
6061
* @param array $tags Tags to associate with this cache entry. If the backend does not support tags, this option can be ignored.
6162
* @param int $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
6263
*
@@ -259,7 +260,14 @@ protected function getFileName(string $entryIdentifier): string
259260
}
260261

261262
try {
262-
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
263+
if (GeneralUtility::makeInstance(Typo3Version::class)->getMajorVersion() < 14) {
264+
/** @var ResourceFactory $resourceFactory */
265+
$resourceFactory = GeneralUtility::makeInstance(ResourceFactory::class);
266+
} else {
267+
/** @var StorageRepository $resourceFactory */
268+
$resourceFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\StorageRepository::class);
269+
}
270+
263271
$storage = $resourceFactory->getDefaultStorage();
264272
$baseName = (string) $storage->sanitizeFileName($baseName);
265273
} catch (\Exception $exception) {

Classes/Cache/StaticDatabaseBackend.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public function getTableDefinitions(): string
5858
ExtensionManagementUtility::extPath('staticfilecache') .
5959
'Resources/Private/Sql/Cache/Backend/' . $large . 'Typo3DatabaseBackendCache.sql'
6060
);
61-
$requiredTableStructures = str_replace('###CACHE_TABLE###', $this->cacheTable, $cacheTableSql) . LF . LF;
61+
$requiredTableStructures = str_replace('###CACHE_TABLE###', $this->cacheTable, $cacheTableSql) . chr(10) . chr(10);
6262
$tagsTableSql = file_get_contents(
6363
ExtensionManagementUtility::extPath('staticfilecache') .
6464
'Resources/Private/Sql/Cache/Backend/' . $large . 'Typo3DatabaseBackendTags.sql'
6565
);
6666

67-
return $requiredTableStructures . str_replace('###TAGS_TABLE###', $this->tagsTable, $tagsTableSql) . LF;
67+
return $requiredTableStructures . str_replace('###TAGS_TABLE###', $this->tagsTable, $tagsTableSql) . chr(10);
6868
}
6969

7070
/**

Tests/Unit/Cache/Listener/AbstractListenerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use SFC\Staticfilecache\Event\CacheRuleEvent;
910
use SFC\Staticfilecache\Tests\Unit\AbstractTest;
11+
use TYPO3\CMS\Core\Http\ServerRequest;
1012

1113
abstract class AbstractListenerTest extends AbstractTest
1214
{
1315
protected function emptyCacheRuleEvent(): CacheRuleEvent
1416
{
1517
return new CacheRuleEvent(
16-
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
18+
new ServerRequest(),
1719
[],
18-
false
20+
false,
21+
$this->getMockBuilder(ResponseInterface::class)->getMock(),
1922
);
2023
}
2124

Tests/Unit/Cache/Listener/CachingAllowedListenerTest.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,34 @@
44

55
namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use SFC\Staticfilecache\Cache\Listener\CachingAllowedListener;
910
use SFC\Staticfilecache\Event\CacheRuleEvent;
11+
use TYPO3\CMS\Core\Http\ServerRequest;
1012
use TYPO3\CMS\Core\Information\Typo3Version;
13+
use TYPO3\CMS\Extbase\Mvc\Request;
1114

1215
class CachingAllowedListenerTest extends AbstractListenerTest
1316
{
1417
public function testNoExplanation(): void
1518
{
16-
$version = $this->getMockBuilder(Typo3Version::class)->disableOriginalConstructor()->getMock();
17-
$version->method('getMajorVersion')->willReturn(12);
18-
19-
$listener = new CachingAllowedListener($version);
19+
$listener = new CachingAllowedListener();
2020

2121
$event = $this->emptyCacheRuleEvent();
2222
$listener($event);
2323

24-
self::assertEquals([], $event->getExplanation());
24+
self::assertEmpty($event->getExplanation());
2525
self::assertEquals(false, $event->isSkipProcessing());
2626

2727
}
2828
protected function emptyCacheRuleEvent(): CacheRuleEvent
2929
{
3030
return new CacheRuleEvent(
31-
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
31+
new ServerRequest(),
3232
[],
33-
false
33+
false,
34+
$this->getMockBuilder(ResponseInterface::class)->getMock(),
3435
);
3536
}
3637
}

Tests/Unit/Cache/Listener/ForceStaticCacheListenerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use SFC\Staticfilecache\Cache\Listener\ForceStaticCacheListener;
910
use SFC\Staticfilecache\Event\CacheRuleEvent;
1011
use TYPO3\CMS\Core\EventDispatcher\NoopEventDispatcher;
12+
use TYPO3\CMS\Core\Http\ServerRequest;
1113

1214
class ForceStaticCacheListenerTest extends AbstractListenerTest
1315
{
@@ -16,9 +18,10 @@ public function testNoExplanation(): void
1618
$listener = new ForceStaticCacheListener(new NoopEventDispatcher());
1719

1820
$cacheRuleEvent = new CacheRuleEvent(
19-
$this->getMockBuilder(ServerRequestInterface::class)->getMock(),
21+
new ServerRequest(),
2022
['dummy'],
21-
false
23+
false,
24+
$this->getMockBuilder(ResponseInterface::class)->getMock()
2225
);
2326

2427
$listener($cacheRuleEvent);

Tests/Unit/Cache/Listener/NoAuthorizationListenerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use SFC\Staticfilecache\Cache\Listener\NoAuthorizationListener;
910
use SFC\Staticfilecache\Event\CacheRuleEvent;
@@ -32,7 +33,8 @@ public function testAddExplanation(): void
3233
$event = new CacheRuleEvent(
3334
$request,
3435
[],
35-
false
36+
false,
37+
$this->getMockBuilder(ResponseInterface::class)->getMock(),
3638
);
3739
$listener($event);
3840

Tests/Unit/Cache/Listener/ValidRequestMethodListenerTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace SFC\Staticfilecache\Tests\Unit\Cache\Listener;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Psr\Http\Message\ServerRequestInterface;
89
use SFC\Staticfilecache\Cache\Listener\NoBackendUserListener;
910
use SFC\Staticfilecache\Cache\Listener\ValidRequestMethodListener;
@@ -26,7 +27,8 @@ public function testNoExplanation(): void
2627
$event = new CacheRuleEvent(
2728
$request,
2829
[],
29-
false
30+
false,
31+
$this->getMockBuilder(ResponseInterface::class)->getMock(),
3032
);
3133
$listener($event);
3234

@@ -44,7 +46,8 @@ public function testExplanationAndSkip(): void
4446
$event = new CacheRuleEvent(
4547
$request,
4648
[],
47-
false
49+
false,
50+
$this->getMockBuilder(ResponseInterface::class)->getMock()
4851
);
4952
$listener($event);
5053

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 5
5+
level: 4
66
reportUnmatchedIgnoredErrors: false
77
paths:
88
- Classes

0 commit comments

Comments
 (0)