浏览代码

Get a few simple tests working.

mark_story 12 年之前
父节点
当前提交
6412c4072c
共有 1 个文件被更改,包括 61 次插入3 次删除
  1. 61 3
      tests/TestCase/Console/Command/OrmCacheShellTest.php

+ 61 - 3
tests/TestCase/Console/Command/OrmCacheShellTest.php

@@ -16,6 +16,7 @@ namespace Cake\Test\TestCase\Console\Command;
 
 
 use Cake\Console\Command\OrmCacheShell;
 use Cake\Console\Command\OrmCacheShell;
 use Cake\Cache\Cache;
 use Cake\Cache\Cache;
+use Cake\Datasource\ConnectionManager;
 use Cake\TestSuite\TestCase;
 use Cake\TestSuite\TestCase;
 
 
 /**
 /**
@@ -24,6 +25,13 @@ use Cake\TestSuite\TestCase;
 class OrmCacheShellTest extends TestCase {
 class OrmCacheShellTest extends TestCase {
 
 
 /**
 /**
+ * Fixtures.
+ *
+ * @var array
+ */
+	public $fixtures = ['core.article', 'core.tag'];
+
+/**
  * setup method
  * setup method
  *
  *
  * @return void
  * @return void
@@ -31,7 +39,29 @@ class OrmCacheShellTest extends TestCase {
 	public function setUp() {
 	public function setUp() {
 		parent::setUp();
 		parent::setUp();
 		$this->io = $this->getMock('Cake\Console\ConsoleIo');
 		$this->io = $this->getMock('Cake\Console\ConsoleIo');
-		$this->Shell = new OrmCacheShell($this->io);
+		$this->shell = new OrmCacheShell($this->io);
+
+		$this->cache = $this->getMock('Cake\Cache\CacheEngine');
+		$this->cache->expects($this->any())
+			->method('init')
+			->will($this->returnValue(true));
+		Cache::config('orm_cache', $this->cache);
+
+		$ds = ConnectionManager::get('test');
+		$ds->cacheMetadata('orm_cache');
+	}
+
+/**
+ * Teardown
+ *
+ * @return void
+ */
+	public function tearDown() {
+		parent::tearDown();
+		Cache::drop('orm_cache');
+
+		$ds = ConnectionManager::get('test');
+		$ds->cacheMetadata(false);
 	}
 	}
 
 
 /**
 /**
@@ -40,7 +70,12 @@ class OrmCacheShellTest extends TestCase {
  * @return void
  * @return void
  */
  */
 	public function testBuildNoArgs() {
 	public function testBuildNoArgs() {
-		$this->markTestIncomplete();
+		$this->cache->expects($this->at(2))
+			->method('write')
+			->with('test_articles');
+
+		$this->shell->params['connection'] = 'test';
+		$this->shell->build();
 	}
 	}
 
 
 /**
 /**
@@ -49,6 +84,22 @@ class OrmCacheShellTest extends TestCase {
  * @return void
  * @return void
  */
  */
 	public function testBuildNamedModel() {
 	public function testBuildNamedModel() {
+		$this->cache->expects($this->once())
+			->method('write')
+			->with('test_articles');
+		$this->cache->expects($this->never())
+			->method('delete');
+
+		$this->shell->params['connection'] = 'test';
+		$this->shell->build('articles');
+	}
+
+/**
+ * Test build() overwrites cached data.
+ *
+ * @return void
+ */
+	public function testBuildOverwritesExistingData() {
 		$this->markTestIncomplete();
 		$this->markTestIncomplete();
 	}
 	}
 
 
@@ -85,7 +136,14 @@ class OrmCacheShellTest extends TestCase {
  * @return void
  * @return void
  */
  */
 	public function testClearNamedModel() {
 	public function testClearNamedModel() {
-		$this->markTestIncomplete();
+		$this->cache->expects($this->never())
+			->method('write');
+		$this->cache->expects($this->once())
+			->method('delete')
+			->with('test_articles');
+
+		$this->shell->params['connection'] = 'test';
+		$this->shell->clear('articles');
 	}
 	}
 
 
 }
 }