8000 Merge branch '3.4' into 4.3 · tigr1991/symfony@eb5e01e · GitHub 10000
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 9, 2025. It is now read-only.

Commit eb5e01e

Browse files
committed
Merge branch '3.4' into 4.3
* 3.4: fix PHP 5.6 compatibility [Cache] fixed TagAwareAdapter returning invalid cache [PropertyInfo] Respect property name case when guessing from public method name
2 parents 6f54733 + fb2a7a3 commit eb5e01e

File tree

5 files changed

+118
-4
lines changed

5 files changed

+118
-4
lines changed

src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,14 @@ public function hasItem($key)
160160
if (!$this->pool->hasItem($key)) {
161161
return false;
162162
}
163-
if (!$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key)->get()) {
163+
164+
$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key);
165+
166+
if (!$itemTags->isHit()) {
167+
return false;
168+
}
169+
170+
if (!$itemTags = $itemTags->get()) {
164171
return true;
165172
}
166173

@@ -300,7 +307,10 @@ private function generateItems($items, array $tagKeys)
300307
}
301308

302309
unset($tagKeys[$key]);
303-
$itemTags[$key] = $item->get() ?: [];
310+
311+
if ($item->isHit()) {
312+
$itemTags[$key] = $item->get() ?: [];
313+
}
304314

305315
if (!$tagKeys) {
306316
$tagVersions = $this->getTagVersions($itemTags);

src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,84 @@ public function testKnownTagVersionsTtl()
9999
$this->assertTrue($pool->getItem('foo')->isHit());
100100
}
101101

102+
public function testTagEntryIsCreatedForItemWithoutTags()
103+
{
104+
$pool = $this->createCachePool();
105+
106+
$itemKey = 'foo';
107+
$item = $pool->getItem($itemKey);
108+
$pool->save($item);
109+
110+
$adapter = new FilesystemAdapter();
111+
$this->assertTrue($adapter->hasItem(TagAwareAdapter::TAGS_PREFIX.$itemKey));
112+
}
113+
114+
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemTags()
115+
{
116+
$pool = $this->createCachePool();
117+
118+
$itemKey = 'foo';
119+
$item = $pool->getItem($itemKey);
120+
$pool->save($item);
121+
122+
$anotherPool = $this->createCachePool();
123+
124+
$adapter = new FilesystemAdapter();
125+
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
126+
127+
$this->assertFalse($anotherPool->hasItem($itemKey));
128+
}
129+
130+
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemTags()
131+
{
132+
$pool = $this->createCachePool();
133+
134+
$itemKey = 'foo';
135+
$item = $pool->getItem($itemKey);
136+
$pool->save($item);
137+
138+
$anotherPool = $this->createCachePool();
139+
140+
$adapter = new FilesystemAdapter();
141+
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair
142+
143+
$item = $anotherPool->getItem($itemKey);
144+
$this->assertFalse($item->isHit());
145+
}
146+
147+
public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
148+
{
149+
$pool = $this->createCachePool();
150+
151+
$itemKey = 'foo';
152+
$item = $pool->getItem($itemKey);
153+
$pool->save($item);
154+
155+
$anotherPool = $this->createCachePool();
156+
157+
$adapter = new FilesystemAdapter();
158+
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
159+
160+
$this->assertFalse($anotherPool->hasItem($itemKey));
161+
}
162+
163+
public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
164+
{
165+
$pool = $this->createCachePool();
166+
167+
$itemKey = 'foo';
168+
$item = $pool->getItem($itemKey);
169+
$pool->save($item);
170+
171+
$anotherPool = $this->createCachePool();
172+
173+
$adapter = new FilesystemAdapter();
174+
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags
175+
176+
$item = $anotherPool->getItem($itemKey);
177+
$this->assertFalse($item->isHit());
178+
}
179+
102180
/**
103181
* @return MockObject|PruneableCacheInterface
104182
*/

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public function getProperties($class, array $context = [])
119119
if (!$propertyName || isset($properties[$propertyName])) {
120120
continue;
121121
}
122-
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
123-
$propertyName = lcfirst($propertyName);
122+
if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) {
123+
$propertyName = $lowerCasedPropertyName;
124124
}
125125
$properties[$propertyName] = $propertyName;
126126
}

src/Symfony/Component/PropertyInfo/Tests/Extractor/ReflectionExtractorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function testGetProperties()
6767
'123',
6868
'self',
6969
'realParent',
70+
'xTotals',
71+
'YT',
7072
'c',
7173
'd',
7274
'e',

src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ class Dummy extends ParentDummy
9393
*/
9494
public $j;
9595

96+
/**
97+
* @var array
98+
*/
99+
private $xTotals;
100+
101+
/**
102+
* @var string
103+
*/
104+
private $YT;
105+
96106
/**
97107
* This should not be removed.
98108
*
@@ -181,4 +191,18 @@ public function setSelf(self $self)
181191
public function setRealParent(parent $realParent)
182192
{
183193
}
194+
195+
/**
196+
* @return array
197+
*/
198+
public function getXTotals()
199+
{
200+
}
201+
202+
/**
203+
* @return string
204+
*/
205+
public function getYT()
206+
{
207+
}
184208
}

0 commit comments

Comments
 (0)
0