Skip to content

Commit

Permalink
Fix orm_cache tool when metadata cache is disabled.
Browse files Browse the repository at this point in the history
Fix error from when metadata cache was refactored. Add missing tests.

Refs #5061
  • Loading branch information
markstory committed Nov 4, 2014
1 parent 5d2d928 commit 5d60a08
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Shell/OrmCacheShell.php
Expand Up @@ -40,10 +40,6 @@ public function build($name = null) {
if (!$schema) {
return false;
}
if (!$schema->cacheMetadata()) {
$this->_io->verbose('Metadata cache was disabled in config. Enabling to write cache.');
$schema->cacheMetadata(true);
}
$tables = [$name];
if (empty($name)) {
$tables = $schema->listTables();
Expand Down Expand Up @@ -71,10 +67,6 @@ public function clear($name = null) {
if (empty($name)) {
$tables = $schema->listTables();
}
if (!$schema->cacheMetadata()) {
$this->_io->verbose('Metadata cache was disabled in config. Enabling to clear cache.');
$schema->cacheMetadata(true);
}
$configName = $schema->cacheMetadata();

foreach ($tables as $table) {
Expand Down Expand Up @@ -104,6 +96,11 @@ protected function _getSchema() {
$this->error($msg);
return false;
}
$config = $source->config();
if (empty($config['cacheMetadata'])) {
$this->_io->verbose('Metadata cache was disabled in config. Enabling to clear cache.');
$source->cacheMetadata(true);
}
return $source->schemaCollection();
}

Expand Down
28 changes: 28 additions & 0 deletions tests/TestCase/Shell/OrmCacheShellTest.php
Expand Up @@ -64,6 +64,34 @@ public function tearDown() {
$ds->cacheMetadata(false);
}

/**
* Test that clear enables the cache if it was disabled.
*
* @return void
*/
public function testClearEnablesMetadataCache() {
$ds = ConnectionManager::get('test');
$ds->cacheMetadata(false);

$this->shell->params['connection'] = 'test';
$this->shell->clear();
$this->assertInstanceOf('Cake\Database\Schema\CachedCollection', $ds->schemaCollection());
}

/**
* Test that build enables the cache if it was disabled.
*
* @return void
*/
public function testBuildEnablesMetadataCache() {
$ds = ConnectionManager::get('test');
$ds->cacheMetadata(false);

$this->shell->params['connection'] = 'test';
$this->shell->build();
$this->assertInstanceOf('Cake\Database\Schema\CachedCollection', $ds->schemaCollection());
}

/**
* Test build() with no args.
*
Expand Down

0 comments on commit 5d60a08

Please sign in to comment.