Skip to content

Commit

Permalink
Merge branch '3.4' into 4.3
Browse files Browse the repository at this point in the history
* 3.4:
  fix PHP 5.6 compatibility
  [Cache] fixed TagAwareAdapter returning invalid cache
  [PropertyInfo] Respect property name case when guessing from public method name
  • Loading branch information
xabbuh committed Oct 14, 2019
2 parents 6f54733 + fb2a7a3 commit eb5e01e
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ public function hasItem($key)
if (!$this->pool->hasItem($key)) {
return false;
}
if (!$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key)->get()) {

$itemTags = $this->pool->getItem(static::TAGS_PREFIX.$key);

if (!$itemTags->isHit()) {
return false;
}

if (!$itemTags = $itemTags->get()) {
return true;
}

Expand Down Expand Up @@ -300,7 +307,10 @@ private function generateItems($items, array $tagKeys)
}

unset($tagKeys[$key]);
$itemTags[$key] = $item->get() ?: [];

if ($item->isHit()) {
$itemTags[$key] = $item->get() ?: [];
}

if (!$tagKeys) {
$tagVersions = $this->getTagVersions($itemTags);
Expand Down
78 changes: 78 additions & 0 deletions src/Symfony/Component/Cache/Tests/Adapter/TagAwareAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,84 @@ public function testKnownTagVersionsTtl()
$this->assertTrue($pool->getItem('foo')->isHit());
}

public function testTagEntryIsCreatedForItemWithoutTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$adapter = new FilesystemAdapter();
$this->assertTrue($adapter->hasItem(TagAwareAdapter::TAGS_PREFIX.$itemKey));
}

public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair

$this->assertFalse($anotherPool->hasItem($itemKey));
}

public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem(TagAwareAdapter::TAGS_PREFIX.$itemKey); //simulate item losing tags pair

$item = $anotherPool->getItem($itemKey);
$this->assertFalse($item->isHit());
}

public function testHasItemReturnsFalseWhenPoolDoesNotHaveItemAndOnlyHasTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags

$this->assertFalse($anotherPool->hasItem($itemKey));
}

public function testGetItemReturnsCacheMissWhenPoolDoesNotHaveItemAndOnlyHasTags()
{
$pool = $this->createCachePool();

$itemKey = 'foo';
$item = $pool->getItem($itemKey);
$pool->save($item);

$anotherPool = $this->createCachePool();

$adapter = new FilesystemAdapter();
$adapter->deleteItem($itemKey); //simulate losing item but keeping tags

$item = $anotherPool->getItem($itemKey);
$this->assertFalse($item->isHit());
}

/**
* @return MockObject|PruneableCacheInterface
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public function getProperties($class, array $context = [])
if (!$propertyName || isset($properties[$propertyName])) {
continue;
}
if (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName)) {
$propertyName = lcfirst($propertyName);
if ($reflectionClass->hasProperty($lowerCasedPropertyName = lcfirst($propertyName)) || (!$reflectionClass->hasProperty($propertyName) && !preg_match('/^[A-Z]{2,}/', $propertyName))) {
$propertyName = $lowerCasedPropertyName;
}
$properties[$propertyName] = $propertyName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function testGetProperties()
'123',
'self',
'realParent',
'xTotals',
'YT',
'c',
'd',
'e',
Expand Down
24 changes: 24 additions & 0 deletions src/Symfony/Component/PropertyInfo/Tests/Fixtures/Dummy.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ class Dummy extends ParentDummy
*/
public $j;

/**
* @var array
*/
private $xTotals;

/**
* @var string
*/
private $YT;

/**
* This should not be removed.
*
Expand Down Expand Up @@ -181,4 +191,18 @@ public function setSelf(self $self)
public function setRealParent(parent $realParent)
{
}

/**
* @return array
*/
public function getXTotals()
{
}

/**
* @return string
*/
public function getYT()
{
}
}

0 comments on commit eb5e01e

Please sign in to comment.