Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/6.3' into 7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bwaidelich committed Jun 5, 2023
2 parents 47945ac + 701072a commit 9d41117
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 5 deletions.
7 changes: 3 additions & 4 deletions Neos.Cache/Classes/Backend/TaggableMultiBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,15 @@ protected function buildSubBackend(string $backendClassName, array $backendOptio
public function flushByTag(string $tag): int
{
$this->prepareBackends();
$count = 0;
$flushed = 0;
foreach ($this->backends as $backend) {
try {
$count |= $backend->flushByTag($tag);
$flushed += $backend->flushByTag($tag);
} catch (\Throwable $t) {
$this->handleError($t);
}
}

return $count;
return $flushed;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Neos.Cache/Classes/Psr/Cache/CachePool.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CachePool implements CacheItemPoolInterface
/**
* Pattern an entry identifier must match.
*/
const PATTERN_ENTRYIDENTIFIER = '/^[a-zA-Z0-9_%\-&]{1,250}$/';
const PATTERN_ENTRYIDENTIFIER = '/^[a-zA-Z0-9_%\-&\.]{1,250}$/';

/**
* @var BackendInterface
Expand Down
48 changes: 48 additions & 0 deletions Neos.Cache/Tests/Unit/Backend/TaggableMultiBackendTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);

namespace Neos\Cache\Tests\Unit\Backend;

include_once(__DIR__ . '/../../BaseTestCase.php');

use Neos\Cache\Backend\NullBackend;
use Neos\Cache\Backend\TaggableMultiBackend;
use Neos\Cache\EnvironmentConfiguration;
use Neos\Cache\Tests\BaseTestCase;

class TaggableMultiBackendTest extends BaseTestCase
{
/**
* @test
*/
public function flushByTagReturnsCountOfFlushedEntries(): void
{
$mockBuilder = $this->getMockBuilder(NullBackend::class);
$firstNullBackendMock = $mockBuilder->getMock();
$secondNullBackendMock = $mockBuilder->getMock();
$thirdNullBackendMock = $mockBuilder->getMock();

$firstNullBackendMock->expects(self::once())->method('flushByTag')->with('foo')->willReturn(2);
$secondNullBackendMock->expects(self::once())->method('flushByTag')->with('foo')->willThrowException(new \RuntimeException());
$thirdNullBackendMock->expects(self::once())->method('flushByTag')->with('foo')->willReturn(3);

$multiBackend = new TaggableMultiBackend($this->getEnvironmentConfiguration(), []);
$this->inject($multiBackend, 'backends', [$firstNullBackendMock, $secondNullBackendMock, $thirdNullBackendMock]);
$this->inject($multiBackend, 'initialized', true);

$result = $multiBackend->flushByTag('foo');
self::assertSame(5, $result);
}

/**
* @return EnvironmentConfiguration
*/
public function getEnvironmentConfiguration(): EnvironmentConfiguration
{
return new EnvironmentConfiguration(
__DIR__ . '~Testing',
'vfs://Foo/',
255
);
}
}
52 changes: 52 additions & 0 deletions Neos.Cache/Tests/Unit/Psr/Cache/CachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

use Neos\Cache\Backend\AbstractBackend;
use Neos\Cache\Backend\BackendInterface;
use Neos\Cache\Psr\Cache\CachePool;
use Neos\Cache\Psr\Cache\CacheItem;
use Neos\Cache\Psr\InvalidArgumentException;
Expand All @@ -23,6 +24,57 @@
*/
class CachePoolTest extends BaseTestCase
{
public function validIdentifiersDataProvider(): array
{
return [
['short'],
['SomeValidIdentifier'],
['withNumbers0123456789'],
['withUnder_score'],
['with.dot'],

// The following tests exceed the minimum requirements of the PSR-6 keys (@see https://www.php-fig.org/psr/psr-6/#definitions)
['dashes-are-allowed'],
['percent%sign'],
['amper&sand'],
['a-string-that-exceeds-the-psr-minimum-maxlength-of-sixtyfour-but-is-shorter-than-twohundredandfifty-characters'],
];
}

/**
* @test
* @dataProvider validIdentifiersDataProvider
*/
public function validIdentifiers(string $identifier): void
{
$mockBackend = $this->getMockBuilder(BackendInterface::class)->getMock();
$cachePool = new CachePool($identifier, $mockBackend);
self::assertInstanceOf(CachePool::class, $cachePool);
}

public function invalidIdentifiersDataProvider(): array
{
return [
[''],
['späcialcharacters'],
['a-string-that-exceeds-the-maximum-allowed-length-of-twohundredandfifty-characters-which-is-pretty-large-as-it-turns-out-so-i-repeat-a-string-that-exceeds-the-maximum-allowed-length-of-twohundredandfifty-characters-still-not-there-wow-crazy-flow-rocks-though'],
];
}

/**
* @test
* @dataProvider invalidIdentifiersDataProvider
*/
public function invalidIdentifiers(string $identifier): void
{
$mockBackend = $this->getMockBuilder(BackendInterface::class)->getMock();

$this->expectException(\InvalidArgumentException::class);
new CachePool($identifier, $mockBackend);
}



/**
* @test
*/
Expand Down

0 comments on commit 9d41117

Please sign in to comment.