-
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.
Merge pull request #6417 from lcobucci/fix-expire-result-cache
Fix expire result cache
- Loading branch information
Showing
4 changed files
with
158 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
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,95 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket; | ||
|
||
use Doctrine\Common\Cache\ArrayCache; | ||
use Doctrine\Tests\OrmFunctionalTestCase; | ||
|
||
/** | ||
* @group 2947 | ||
*/ | ||
class GH2947Test extends OrmFunctionalTestCase | ||
{ | ||
protected function setUp() | ||
{ | ||
$this->resultCacheImpl = new ArrayCache(); | ||
|
||
parent::setUp(); | ||
|
||
$this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH2947Car::class)]); | ||
} | ||
|
||
public function testIssue() | ||
{ | ||
$this->createData(); | ||
$initialQueryCount = $this->getCurrentQueryCount(); | ||
|
||
$query = $this->createQuery(); | ||
self::assertEquals('BMW', (string) $query->getSingleResult()); | ||
self::assertEquals($initialQueryCount + 1, $this->getCurrentQueryCount()); | ||
|
||
$this->updateData(); | ||
self::assertEquals('BMW', (string) $query->getSingleResult()); | ||
self::assertEquals($initialQueryCount + 2, $this->getCurrentQueryCount()); | ||
|
||
$query->expireResultCache(true); | ||
self::assertEquals('Dacia', (string) $query->getSingleResult()); | ||
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); | ||
|
||
$query->expireResultCache(false); | ||
self::assertEquals('Dacia', (string) $query->getSingleResult()); | ||
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); | ||
} | ||
|
||
private function createQuery() | ||
{ | ||
return $this->_em->createQueryBuilder() | ||
->select('car') | ||
->from(GH2947Car::class, 'car') | ||
->getQuery() | ||
->useResultCache(true, 3600, 'foo-cache-id'); | ||
} | ||
|
||
private function createData() | ||
{ | ||
$this->_em->persist(new GH2947Car('BMW')); | ||
$this->_em->flush(); | ||
$this->_em->clear(); | ||
} | ||
|
||
private function updateData() | ||
{ | ||
$this->_em->createQueryBuilder() | ||
->update(GH2947Car::class, 'car') | ||
->set('car.brand', ':newBrand') | ||
->where('car.brand = :oldBrand') | ||
->setParameter('newBrand', 'Dacia') | ||
->setParameter('oldBrand', 'BMW') | ||
->getQuery() | ||
->execute(); | ||
} | ||
} | ||
|
||
/** | ||
* @Entity | ||
* @Table(name="GH2947_car") | ||
*/ | ||
class GH2947Car | ||
{ | ||
/** | ||
* @Id | ||
* @Column(type="string", length=25) | ||
* @GeneratedValue(strategy="NONE") | ||
*/ | ||
public $brand; | ||
|
||
public function __construct(string $brand) | ||
{ | ||
$this->brand = $brand; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->brand; | ||
} | ||
} |
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
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