Skip to content

Commit

Permalink
Update remaining tests and fix path issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 19, 2014
1 parent 4e003bb commit eac89bf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 41 deletions.
32 changes: 16 additions & 16 deletions src/Console/Command/Task/FixtureTask.php
Expand Up @@ -30,7 +30,7 @@ class FixtureTask extends BakeTask {
*
* @var array
*/
public $tasks = ['DbConfig', 'Model', 'Template'];
public $tasks = ['Model', 'Template'];

/**
* path to fixtures directory
Expand All @@ -48,7 +48,7 @@ class FixtureTask extends BakeTask {
*/
public function __construct($stdout = null, $stderr = null, $stdin = null) {
parent::__construct($stdout, $stderr, $stdin);
$this->path = APP . 'Test/Fixture/';
$this->path = ROOT . '/Test/Fixture/';
}

/**
Expand Down Expand Up @@ -90,6 +90,9 @@ public function getOptionParser() {
'help' => __d('cake_console', 'Used with --count and <name>/all commands to pull [n] records from the live tables, where [n] is either --count or the default of 10.'),
'short' => 'r',
'boolean' => true
])->addOption('conditions', [
'help' => __d('cake_console', 'The SQL snippet to use when importing records.'),
'default' => '1=1',
]);

return $parser;
Expand Down Expand Up @@ -430,14 +433,18 @@ protected function _makeRecordString($records) {
* @return array Array of records.
*/
protected function _getRecordsFromTable($modelName, $useTable = null) {
$condition = 'WHERE 1=1';
$recordCount = (isset($this->params['count']) ? $this->params['count'] : 10);
$model = TableRegistry::get($modelName, [
'table' => $useTable,
'connection' => ConnectionManager::get($this->connection)
]);
$conditions = (isset($this->params['conditions']) ? $this->params['conditions'] : '1=1');
if (TableRegistry::exists($modelName)) {
$model = TableRegistry::get($modelName);
} else {
$model = TableRegistry::get($modelName, [
'table' => $useTable,
'connection' => ConnectionManager::get($this->connection)
]);
}
$records = $model->find('all', [
'conditions' => $condition,
'conditions' => $conditions,
'recursive' => -1,
'limit' => $recordCount
]);
Expand All @@ -446,14 +453,7 @@ protected function _getRecordsFromTable($modelName, $useTable = null) {
$alias = $model->alias();
$out = [];
foreach ($records as $record) {
$row = [];
foreach ($record[$model->alias] as $field => $value) {
if ($schema->columnType($field) === 'boolean') {
$value = (int)(bool)$value;
}
$row[$field] = $value;
}
$out[] = $row;
$out[] = $record->toArray();
}
return $out;
}
Expand Down
32 changes: 12 additions & 20 deletions tests/TestCase/Console/Command/Task/FixtureTaskTest.php
Expand Up @@ -78,7 +78,7 @@ public function testConstruct() {
$in = $this->getMock('Cake\Console\ConsoleInput', array(), array(), '', false);

$Task = new FixtureTask($out, $out, $in);
$this->assertEquals(APP . 'Test/Fixture/', $Task->path);
$this->assertEquals(ROOT . '/Test/Fixture/', $Task->path);
}

/**
Expand Down Expand Up @@ -126,16 +126,13 @@ public function testImportOptionsWithRecords() {
* @return void
*/
public function testImportRecordsFromDatabaseWithConditionsPoo() {
$this->markTestIncomplete('not done');
$this->Task->interactive = true;
$this->Task->expects($this->at(0))->method('in')
->will($this->returnValue('WHERE 1=1'));

$this->Task->connection = 'test';
$this->Task->path = '/my/path/';

$result = $this->Task->bake('Article', false, array(
'fromTable' => true, 'schema' => 'Article', 'records' => false
$result = $this->Task->bake('Articles', false, array(
'fromTable' => true,
'schema' => 'Articles',
'records' => false
));

$this->assertContains('namespace App\Test\Fixture;', $result);
Expand Down Expand Up @@ -165,19 +162,13 @@ public function testImportOptionsAlternateConnection() {
* @return void
*/
public function testImportRecordsNoEscaping() {
$this->markTestIncomplete('not done');
$db = ConnectionManager::get('test');
if ($db instanceof Sqlserver) {
$this->markTestSkipped('This test does not run on SQLServer');
}

$articles = TableRegistry::get('Articles');
$articles->updateAll(['body' => "'Body \"value\"'"]);

$this->Task->interactive = true;
$this->Task->expects($this->at(0))
->method('in')
->will($this->returnValue('WHERE 1=1 LIMIT 10'));
$articles->updateAll(['body' => "Body \"value\""], []);

$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
Expand Down Expand Up @@ -239,21 +230,22 @@ public function testExecuteIntoAll() {
* @return void
*/
public function testAllWithCountAndRecordsFlags() {
$this->markTestIncomplete('not done');
$this->Task->connection = 'test';
$this->Task->path = '/my/path/';
$this->Task->args = array('all');
$this->Task->params = array('count' => 10, 'records' => true);
$this->Task->args = ['all'];
$this->Task->params = ['count' => 10, 'records' => true];

$this->Task->Model->expects($this->any())->method('listAll')
->will($this->returnValue(array('Articles', 'comments')));

$filename = '/my/path/ArticleFixture.php';
$this->Task->expects($this->at(0))->method('createFile')
$this->Task->expects($this->at(0))
->method('createFile')
->with($filename, $this->stringContains("'title' => 'Third Article'"));

$filename = '/my/path/CommentFixture.php';
$this->Task->expects($this->at(1))->method('createFile')
$this->Task->expects($this->at(1))
->method('createFile')
->with($filename, $this->stringContains("'comment' => 'First Comment for First Article'"));
$this->Task->expects($this->exactly(2))->method('createFile');

Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -54,6 +54,7 @@ public function setUp() {
);
$this->Task->connection = 'test';
$this->_setupOtherMocks();
TableRegistry::clear();
}

/**
Expand Down
6 changes: 1 addition & 5 deletions tests/TestCase/Console/Command/Task/TemplateTaskTest.php
@@ -1,9 +1,5 @@
<?php
/**
* TemplateTask file
*
* Test Case for TemplateTask generation shell task
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand All @@ -24,7 +20,6 @@

/**
* TemplateTaskTest class
*
*/
class TemplateTaskTest extends TestCase {

Expand Down Expand Up @@ -115,6 +110,7 @@ public function testGenerateWithTemplateFallbacks() {
$this->Task->initialize();
$this->Task->params['theme'] = 'test';
$this->Task->set(array(
'name' => 'Article',
'model' => 'Article',
'table' => 'articles',
'import' => false,
Expand Down

0 comments on commit eac89bf

Please sign in to comment.