Skip to content

Commit

Permalink
fixup! Support for PSR-6 result caches
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Sep 10, 2021
1 parent a71fee7 commit cd1f621
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions tests/Doctrine/Tests/ORM/AbstractQueryTest.php
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');
}
}

0 comments on commit cd1f621

Please sign in to comment.