1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @group 2947 |
9
|
|
|
*/ |
10
|
|
|
class GH2947Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
$this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH2947Car::class)]); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testIssue() |
20
|
|
|
{ |
21
|
|
|
$this->createData(); |
22
|
|
|
$initialQueryCount = $this->getCurrentQueryCount(); |
23
|
|
|
|
24
|
|
|
$query = $this->createQuery(); |
25
|
|
|
self::assertEquals('BMW', (string) $query->getSingleResult()); |
26
|
|
|
self::assertEquals($initialQueryCount + 1, $this->getCurrentQueryCount()); |
27
|
|
|
|
28
|
|
|
$this->alterData(); |
29
|
|
|
self::assertEquals('BMW', (string) $query->getSingleResult()); |
30
|
|
|
self::assertEquals($initialQueryCount + 2, $this->getCurrentQueryCount()); |
31
|
|
|
|
32
|
|
|
$query->expireResultCache(true); |
33
|
|
|
self::assertEquals('Dacia', (string) $query->getSingleResult()); |
34
|
|
|
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); |
35
|
|
|
|
36
|
|
|
$query->expireResultCache(false); |
37
|
|
|
self::assertEquals('Dacia', (string) $query->getSingleResult()); |
38
|
|
|
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function createQuery() |
42
|
|
|
{ |
43
|
|
|
return $this->_em->createQueryBuilder() |
44
|
|
|
->select('car') |
45
|
|
|
->from(GH2947Car::class, 'car') |
46
|
|
|
->getQuery() |
47
|
|
|
->useResultCache(true, 3600, 'foo-cache-id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
private function createData() |
51
|
|
|
{ |
52
|
|
|
$this->_em->persist(new GH2947Car('BMW', '7 Series')); |
53
|
|
|
$this->_em->flush(); |
54
|
|
|
$this->_em->clear(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private function alterData() |
58
|
|
|
{ |
59
|
|
|
$this->_em->createQueryBuilder() |
60
|
|
|
->update(GH2947Car::class, 'car') |
61
|
|
|
->set('car.brand', ':newBrand') |
62
|
|
|
->where('car.brand = :oldBrand') |
63
|
|
|
->setParameter('newBrand', 'Dacia') |
64
|
|
|
->setParameter('oldBrand', 'BMW') |
65
|
|
|
->getQuery() |
66
|
|
|
->execute(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Entity |
72
|
|
|
* @Table(name="GH2947_car") |
73
|
|
|
*/ |
74
|
|
|
class GH2947Car |
75
|
|
|
{ |
76
|
|
|
/** |
77
|
|
|
* @Id |
78
|
|
|
* @Column(type="string", length=25) |
79
|
|
|
* @GeneratedValue(strategy="NONE") |
80
|
|
|
*/ |
81
|
|
|
public $brand; |
82
|
|
|
|
83
|
|
|
public function __construct($brand) |
84
|
|
|
{ |
85
|
|
|
$this->brand = $brand; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function __toString() |
89
|
|
|
{ |
90
|
|
|
return $this->brand; |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|