Added test for non-pruneable cache adapters

This commit is contained in:
Chris Kankiewicz
2021-09-18 23:32:35 -07:00
parent 723fad1b6d
commit 8af26cd927

View File

@@ -6,8 +6,7 @@ use App\Middlewares\PruneCacheMiddleware;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\PhpFilesAdapter;
use Symfony\Component\Cache\Adapter;
use Symfony\Contracts\Cache\CacheInterface;
use Tests\TestCase;
@@ -34,11 +33,38 @@ class PruneCacheMiddlewareTest extends TestCase
);
}
/** @dataProvider nonPruneableCacheAdapters */
public function test_it_does_not_prune_the_cache_when_using_a_non_prunable_adapter(string $cacheAdapter): void
{
/** @var CacheInterface&MockObject */
$cache = $this->getMockBuilder($cacheAdapter)
->disableOriginalConstructor()
->addMethods(['prune'])
->getMock();
$cache->expects($this->never())->method('prune');
(new PruneCacheMiddleware($this->config, $cache))(
$this->createMock(ServerRequestInterface::class),
$this->createMock(RequestHandlerInterface::class)
);
}
public function pruneableCacheAdapters(): array
{
return [
[FilesystemAdapter::class],
[PhpFilesAdapter::class],
[Adapter\FilesystemAdapter::class],
[Adapter\PhpFilesAdapter::class],
];
}
public function nonPruneableCacheAdapters(): array
{
return [
[Adapter\ApcuAdapter::class],
[Adapter\ArrayAdapter::class],
[Adapter\MemcachedAdapter::class],
[Adapter\RedisAdapter::class],
];
}
}