Issue #2492429 by mikeryan, neclimdul: Migration count caching broken

8.0.x
webchick 2015-08-03 21:35:30 -07:00
parent 45457ced1f
commit 967b16fd77
2 changed files with 8 additions and 5 deletions

View File

@ -423,7 +423,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
// class to get the count from the source. // class to get the count from the source.
if ($refresh || !$this->cacheCounts) { if ($refresh || !$this->cacheCounts) {
$count = $this->getIterator()->count(); $count = $this->getIterator()->count();
$this->getCache()->set($this->cacheKey, $count, 'cache'); $this->getCache()->set($this->cacheKey, $count);
} }
else { else {
// Caching is in play, first try to retrieve a cached count. // Caching is in play, first try to retrieve a cached count.
@ -436,7 +436,7 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter
// No cached count, ask the derived class to count 'em up, and cache // No cached count, ask the derived class to count 'em up, and cache
// the result. // the result.
$count = $this->getIterator()->count(); $count = $this->getIterator()->count();
$this->getCache()->set($this->cacheKey, $count, 'cache'); $this->getCache()->set($this->cacheKey, $count);
} }
} }
return $count; return $count;

View File

@ -7,6 +7,7 @@
namespace Drupal\Tests\migrate\Unit; namespace Drupal\Tests\migrate\Unit;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\Plugin\MigrateIdMapInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface;
@ -139,10 +140,12 @@ class MigrateSourceTest extends MigrateTestCase {
* Test that the source count is correct. * Test that the source count is correct.
*/ */
public function testCount() { public function testCount() {
// Mock the cache to validate set() receives appropriate arguments.
$container = new ContainerBuilder(); $container = new ContainerBuilder();
$container->register('cache.migrate', 'Drupal\Core\Cache\NullBackend') $cache = $this->getMock(CacheBackendInterface::class);
->setArguments(['migrate']); $cache->expects($this->any())->method('set')
->with($this->isType('string'), $this->isType('int'), $this->isType('int'));
$container->set('cache.migrate', $cache);
\Drupal::setContainer($container); \Drupal::setContainer($container);
// Test that the basic count works. // Test that the basic count works.