-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Support for PSR-6 result caches
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM; | ||
|
||
use Doctrine\Common\Cache\Cache; | ||
use Doctrine\DBAL\Cache\QueryCacheProfile; | ||
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; | ||
use Doctrine\ORM\AbstractQuery; | ||
use Doctrine\ORM\Configuration; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Cache\CacheItemPoolInterface; | ||
|
||
use function method_exists; | ||
|
||
final class AbstractQueryTest extends TestCase | ||
{ | ||
use VerifyDeprecations; | ||
|
||
public function testItMakesHydrationCacheProfilesAwareOfTheResultCacheDriver(): void | ||
{ | ||
if (method_exists(QueryCacheProfile::class, 'setResultCache')) { | ||
self::markTestSkipped('this test is meant for DBAL < 3.2'); | ||
} | ||
|
||
$configuration = new Configuration(); | ||
$configuration->setHydrationCacheImpl($this->createStub(Cache::class)); | ||
$entityManager = $this->createStub(EntityManagerInterface::class); | ||
$entityManager->method('getConfiguration')->willReturn($configuration); | ||
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]); | ||
$cacheProfile = new QueryCacheProfile(); | ||
|
||
$query->setHydrationCacheProfile($cacheProfile); | ||
self::assertNotNull($query->getHydrationCacheProfile()->getResultCacheDriver()); | ||
} | ||
|
||
/** | ||
* @requires function Doctrine\DBAL\Cache\QueryCacheProfile::setResultCache | ||
*/ | ||
public function testItMakesHydrationCacheProfilesAwareOfTheResultCache(): void | ||
{ | ||
$configuration = new Configuration(); | ||
$configuration->setHydrationCacheImpl($this->createStub(Cache::class)); | ||
$entityManager = $this->createStub(EntityManagerInterface::class); | ||
$entityManager->method('getConfiguration')->willReturn($configuration); | ||
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]); | ||
$cacheProfile = new QueryCacheProfile(); | ||
|
||
$query->setHydrationCacheProfile($cacheProfile); | ||
self::assertNotNull($query->getHydrationCacheProfile()->getResultCache()); | ||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4620'); | ||
} | ||
|
||
public function testItMakesResultCacheProfilesAwareOfTheResultCacheDriver(): void | ||
{ | ||
if (method_exists(QueryCacheProfile::class, 'setResultCache')) { | ||
self::markTestSkipped('this test is meant for DBAL < 3.2'); | ||
} | ||
|
||
$configuration = new Configuration(); | ||
$configuration->setResultCacheImpl($this->createStub(Cache::class)); | ||
$entityManager = $this->createStub(EntityManagerInterface::class); | ||
$entityManager->method('getConfiguration')->willReturn($configuration); | ||
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]); | ||
$cacheProfile = new QueryCacheProfile(); | ||
|
||
$query->setHydrationCacheProfile($cacheProfile); | ||
self::assertNotNull($query->getResultCacheDriver()); | ||
} | ||
|
||
/** | ||
* @requires function Doctrine\DBAL\Cache\QueryCacheProfile::setResultCache | ||
*/ | ||
public function testItMakesResultCacheProfilesAwareOfTheResultCache(): void | ||
{ | ||
$configuration = new Configuration(); | ||
$configuration->setResultCache($this->createStub(CacheItemPoolInterface::class)); | ||
$entityManager = $this->createStub(EntityManagerInterface::class); | ||
$entityManager->method('getConfiguration')->willReturn($configuration); | ||
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]); | ||
$cacheProfile = new QueryCacheProfile(); | ||
|
||
$query->setHydrationCacheProfile($cacheProfile); | ||
self::assertNotNull($query->getResultCacheDriver()); | ||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4620'); | ||
} | ||
|
||
/** | ||
* @requires function Doctrine\DBAL\Cache\QueryCacheProfile::setResultCache | ||
*/ | ||
public function testSettingTheResultCacheIsPossibleWithoutCallingDeprecatedAPIs(): void | ||
{ | ||
$entityManager = $this->createStub(EntityManagerInterface::class); | ||
$entityManager->method('getConfiguration')->willReturn(new Configuration()); | ||
$query = $this->getMockForAbstractClass(AbstractQuery::class, [$entityManager]); | ||
|
||
$query->setResultCache($this->createStub(CacheItemPoolInterface::class)); | ||
self::assertNotNull($query->getResultCacheDriver()); | ||
$this->expectNoDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/4620'); | ||
} | ||
} |