Skip to content

Commit

Permalink
Fix broken CacheResolver tests (#650)
Browse files Browse the repository at this point in the history
Since September'2015 Doctrine doesn't always save namespace version in
the cache itself:
doctrine/cache@ecc4af1

Relying on such kind of implementation detail in a test that is supposed
to check if several keys are saved in a cache is kind of pointless, so it
makes sense to ignore the cache key that holds a namespace version
  • Loading branch information
kamazee committed Oct 30, 2015
1 parent 888b6c5 commit 05a3c89
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions Tests/Imagine/Cache/Resolver/CacheResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,16 @@ public function testRemoveSinglePathCacheOnRemove()
$cacheResolver->resolve($this->path, $this->filter);

/*
* Three items:
* Checking 2 items:
* * The result of one resolve execution.
* * The index of entity.
* * The array cache meta info
*/
$this->assertCount(3, $this->readAttribute($cache, 'data'));
$this->assertCount(2, $this->getCacheEntries($cache));

$cacheResolver->remove(array($this->path), array($this->filter));

// Cache including index has been removed.
$this->assertCount(1, $this->readAttribute($cache, 'data'));
$this->assertCount(0, $this->getCacheEntries($cache));
}

public function testRemoveAllFilterCacheOnRemove()
Expand All @@ -167,16 +166,33 @@ public function testRemoveAllFilterCacheOnRemove()
$cacheResolver->resolve('aPathBar', 'thumbnail_100x100');

/*
* Seven items:
* Checking 6 items:
* * The result of four resolve execution.
* * The index of two entities.
* * The array cache meta info
*/
$this->assertCount(7, $this->readAttribute($cache, 'data'));
$this->assertCount(6, $this->getCacheEntries($cache));

$cacheResolver->remove(array(), array('thumbnail_233x233'));

// Cache including index has been removed.
$this->assertCount(4, $this->readAttribute($cache, 'data'));
$this->assertCount(3, $this->getCacheEntries($cache));
}

/**
* There's an intermittent cache entry which is a cache namespace
* version, it may or may not be there depending on doctrine-cache
* version. There's no point in checking it anyway since it's a detail
* of doctrine cache implementation
*
* @param ArrayCache $cache
*
* @return array
*/
private function getCacheEntries(ArrayCache $cache)
{
$cacheEntries = $this->readAttribute($cache, 'data');
unset($cacheEntries['DoctrineNamespaceCacheKey[]']);

return $cacheEntries;
}
}

0 comments on commit 05a3c89

Please sign in to comment.