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
This commit is contained in:
Christian Flothmann 2019-10-14 14:12:55 +02:00
commit eb5e01e063
5 changed files with 118 additions and 4 deletions

View File

@ -160,7 +160,14 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
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;
}
@ -300,7 +307,10 @@ class TagAwareAdapter implements TagAwareAdapterInterface, TagAwareCacheInterfac
}
unset($tagKeys[$key]);
$itemTags[$key] = $item->get() ?: [];
if ($item->isHit()) {
$itemTags[$key] = $item->get() ?: [];
}
if (!$tagKeys) {
$tagVersions = $this->getTagVersions($itemTags);

View File

@ -99,6 +99,84 @@ class TagAwareAdapterTest extends AdapterTestCase
$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
*/

View File

@ -119,8 +119,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
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;
}

View File

@ -67,6 +67,8 @@ class ReflectionExtractorTest extends TestCase
'123',
'self',
'realParent',
'xTotals',
'YT',
'c',
'd',
'e',

View File

@ -93,6 +93,16 @@ class Dummy extends ParentDummy
*/
public $j;
/**
* @var array
*/
private $xTotals;
/**
* @var string
*/
private $YT;
/**
* This should not be removed.
*
@ -181,4 +191,18 @@ class Dummy extends ParentDummy
public function setRealParent(parent $realParent)
{
}
/**
* @return array
*/
public function getXTotals()
{
}
/**
* @return string
*/
public function getYT()
{
}
}