mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Updating ModelTask test case to PHPUnit.
This commit is contained in:
parent
ad8d5fa29b
commit
9cdf11a02a
1 changed files with 213 additions and 139 deletions
|
@ -36,23 +36,6 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'fixture.php';
|
||||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||||
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ShellDispatcher', 'TestModelTaskMockShellDispatcher',
|
|
||||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
|
||||||
);
|
|
||||||
Mock::generatePartial(
|
|
||||||
'ModelTask', 'MockModelTask',
|
|
||||||
array('in', 'out', 'hr', 'err', 'createFile', '_stop', '_checkUnitTest')
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate(
|
|
||||||
'Model', 'MockModelTaskModel'
|
|
||||||
);
|
|
||||||
|
|
||||||
Mock::generate(
|
|
||||||
'FixtureTask', 'MockModelTaskFixtureTask'
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ModelTaskTest class
|
* ModelTaskTest class
|
||||||
*
|
*
|
||||||
|
@ -75,15 +58,42 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function startTest() {
|
public function startTest() {
|
||||||
$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
|
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||||
$this->Task =& new MockModelTask($this->Dispatcher);
|
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||||
|
));
|
||||||
|
$this->Task = $this->getMock('ModelTask',
|
||||||
|
array('in', 'err', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->_setupOtherMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup a mock that has out mocked. Normally this is not used as it makes $this->at() really tricky.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _useMockedOut() {
|
||||||
|
$this->Task = $this->getMock('ModelTask',
|
||||||
|
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
||||||
|
array(&$this->Dispatcher)
|
||||||
|
);
|
||||||
|
$this->_setupOtherMocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets up the rest of the dependencies for Model Task
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function _setupOtherMocks() {
|
||||||
|
$this->Task->Fixture = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
|
||||||
|
$this->Task->Test = $this->getMock('FixtureTask', array(), array(&$this->Dispatcher));
|
||||||
|
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||||
|
|
||||||
$this->Task->name = 'ModelTask';
|
$this->Task->name = 'ModelTask';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Dispatch =& $this->Dispatcher;
|
|
||||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
|
||||||
$this->Task->Fixture =& new MockModelTaskFixtureTask();
|
|
||||||
$this->Task->Test =& new MockModelTaskFixtureTask();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,21 +112,24 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testListAll() {
|
public function testListAll() {
|
||||||
$this->Task->expectAt(1, 'out', array('1. Article'));
|
$this->_useMockedOut();
|
||||||
$this->Task->expectAt(2, 'out', array('2. ArticlesTag'));
|
|
||||||
$this->Task->expectAt(3, 'out', array('3. CategoryThread'));
|
$this->Task->expects($this->at(1))->method('out')->with('1. Article');
|
||||||
$this->Task->expectAt(4, 'out', array('4. Comment'));
|
$this->Task->expects($this->at(2))->method('out')->with('2. ArticlesTag');
|
||||||
$this->Task->expectAt(5, 'out', array('5. Tag'));
|
$this->Task->expects($this->at(3))->method('out')->with('3. CategoryThread');
|
||||||
|
$this->Task->expects($this->at(4))->method('out')->with('4. Comment');
|
||||||
|
$this->Task->expects($this->at(5))->method('out')->with('5. Tag');
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(7))->method('out')->with('1. Article');
|
||||||
|
$this->Task->expects($this->at(8))->method('out')->with('2. ArticlesTag');
|
||||||
|
$this->Task->expects($this->at(9))->method('out')->with('3. CategoryThread');
|
||||||
|
$this->Task->expects($this->at(10))->method('out')->with('4. Comment');
|
||||||
|
$this->Task->expects($this->at(11))->method('out')->with('5. Tag');
|
||||||
|
|
||||||
$result = $this->Task->listAll('test_suite');
|
$result = $this->Task->listAll('test_suite');
|
||||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->expectAt(7, 'out', array('1. Article'));
|
|
||||||
$this->Task->expectAt(8, 'out', array('2. ArticlesTag'));
|
|
||||||
$this->Task->expectAt(9, 'out', array('3. CategoryThread'));
|
|
||||||
$this->Task->expectAt(10, 'out', array('4. Comment'));
|
|
||||||
$this->Task->expectAt(11, 'out', array('5. Tag'));
|
|
||||||
|
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$result = $this->Task->listAll();
|
$result = $this->Task->listAll();
|
||||||
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
$expected = array('articles', 'articles_tags', 'category_threads', 'comments', 'tags');
|
||||||
|
@ -128,26 +141,41 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetName() {
|
public function testGetNameQuit() {
|
||||||
$this->Task->setReturnValue('in', 1);
|
$this->Task->expects($this->once())->method('in')->will($this->returnValue('q'));
|
||||||
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
|
||||||
$this->Task->expectOnce('_stop');
|
|
||||||
$this->Task->getName('test_suite');
|
$this->Task->getName('test_suite');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test getName with a valid option.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetNameValidOption() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(4));
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$expected = 'Article';
|
$expected = 'Article';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(2, 'in', 4);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$expected = 'Comment';
|
$expected = 'Comment';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that an out of bounds option causes an error.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetNameWithOutOfBoundsOption() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue(10));
|
||||||
|
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->once())->method('err');
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 10);
|
|
||||||
$result = $this->Task->getName('test_suite');
|
$result = $this->Task->getName('test_suite');
|
||||||
$this->Task->expectOnce('err');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,13 +184,20 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testGetTableName() {
|
public function testGetTableName() {
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
$result = $this->Task->getTable('Article', 'test_suite');
|
$result = $this->Task->getTable('Article', 'test_suite');
|
||||||
$expected = 'articles';
|
$expected = 'articles';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
/**
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'my_table');
|
* test gettting a custom table name.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testGetTableNameCustom() {
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('my_table'));
|
||||||
$result = $this->Task->getTable('Article', 'test_suite');
|
$result = $this->Task->getTable('Article', 'test_suite');
|
||||||
$expected = 'my_table';
|
$expected = 'my_table';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -215,10 +250,8 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testInteractiveFieldValidation() {
|
public function testInteractiveFieldValidation() {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '20');
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
->will($this->onConsecutiveCalls('20', 'y', '16', 'n'));
|
||||||
$this->Task->setReturnValueAt(2, 'in', '16');
|
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'n');
|
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
|
$expected = array('notempty' => 'notempty', 'maxlength' => 'maxlength');
|
||||||
|
@ -231,12 +264,15 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
function testInteractiveFieldValidationWithBogusResponse() {
|
function testInteractiveFieldValidationWithBogusResponse() {
|
||||||
|
$this->_useMockedOut();
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '999999');
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', '20');
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'n');
|
->will($this->onConsecutiveCalls('999999', '20', 'n'));
|
||||||
$this->Task->expectAt(4, 'out', array(new PatternExpectation('/make a valid/')));
|
|
||||||
|
$this->Task->expects($this->at(7))->method('out')
|
||||||
|
->with(new PHPUnit_Framework_Constraint_PCREMatch('/make a valid/'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('notempty' => 'notempty');
|
$expected = array('notempty' => 'notempty');
|
||||||
|
@ -251,8 +287,8 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
function testInteractiveFieldValidationWithRegexp() {
|
function testInteractiveFieldValidationWithRegexp() {
|
||||||
$this->Task->initValidations();
|
$this->Task->initValidations();
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->setReturnValueAt(0, 'in', '/^[a-z]{0,9}$/');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('/^[a-z]{0,9}$/'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('n'));
|
||||||
|
|
||||||
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
|
||||||
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
$expected = array('a_z_0_9' => '/^[a-z]{0,9}$/');
|
||||||
|
@ -265,9 +301,9 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testNonInteractiveDoValidation() {
|
public function testNonInteractiveDoValidation() {
|
||||||
$Model =& new MockModelTaskModel();
|
$Model = $this->getMock('Model');
|
||||||
$Model->primaryKey = 'id';
|
$Model->primaryKey = 'id';
|
||||||
$Model->setReturnValue('schema', array(
|
$Model->expects($this->any())->method('schema')->will($this->returnValue(array(
|
||||||
'id' => array(
|
'id' => array(
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'length' => 11,
|
'length' => 11,
|
||||||
|
@ -299,7 +335,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
'length' => '',
|
'length' => '',
|
||||||
'null' => false,
|
'null' => false,
|
||||||
)
|
)
|
||||||
));
|
)));
|
||||||
$this->Task->interactive = false;
|
$this->Task->interactive = false;
|
||||||
|
|
||||||
$result = $this->Task->doValidation($Model);
|
$result = $this->Task->doValidation($Model);
|
||||||
|
@ -331,8 +367,11 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
'two' => array(),
|
'two' => array(),
|
||||||
'key' => array('key' => 'primary')
|
'key' => array('key' => 'primary')
|
||||||
);
|
);
|
||||||
$this->Task->expectAt(0, 'in', array('*', null, 'key'));
|
$anything = new PHPUnit_Framework_Constraint_IsAnything();
|
||||||
$this->Task->setReturnValue('in', 'my_field');
|
$this->Task->expects($this->once())->method('in')
|
||||||
|
->with($anything, null, 'key')
|
||||||
|
->will($this->returnValue('my_field'));
|
||||||
|
|
||||||
$result = $this->Task->findPrimaryKey($fields);
|
$result = $this->Task->findPrimaryKey($fields);
|
||||||
$expected = 'my_field';
|
$expected = 'my_field';
|
||||||
$this->assertEqual($result, $expected);
|
$this->assertEqual($result, $expected);
|
||||||
|
@ -343,17 +382,28 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testFindDisplayField() {
|
public function testFindDisplayFieldNone() {
|
||||||
$fields = array('id' => array(), 'tagname' => array(), 'body' => array(),
|
$fields = array(
|
||||||
'created' => array(), 'modified' => array());
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
||||||
|
'created' => array(), 'modified' => array()
|
||||||
$this->Task->setReturnValue('in', 'n');
|
);
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'n');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('n'));
|
||||||
$result = $this->Task->findDisplayField($fields);
|
$result = $this->Task->findDisplayField($fields);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
}
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
/**
|
||||||
$this->Task->setReturnValueAt(2, 'in', 2);
|
* Test finding a displayname from user input
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFindDisplayName() {
|
||||||
|
$fields = array(
|
||||||
|
'id' => array(), 'tagname' => array(), 'body' => array(),
|
||||||
|
'created' => array(), 'modified' => array()
|
||||||
|
);
|
||||||
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
|
||||||
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(2));
|
||||||
$result = $this->Task->findDisplayField($fields);
|
$result = $this->Task->findDisplayField($fields);
|
||||||
$this->assertEqual($result, 'tagname');
|
$this->assertEqual($result, 'tagname');
|
||||||
}
|
}
|
||||||
|
@ -507,7 +557,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testBakeFixture() {
|
public function testBakeFixture() {
|
||||||
$this->Task->plugin = 'test_plugin';
|
$this->Task->plugin = 'test_plugin';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Fixture->expectAt(0, 'bake', array('Article', 'articles'));
|
$this->Task->Fixture->expects($this->at(0))->method('bake')->with('Article', 'articles');
|
||||||
$this->Task->bakeFixture('Article', 'articles');
|
$this->Task->bakeFixture('Article', 'articles');
|
||||||
|
|
||||||
$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
|
$this->assertEqual($this->Task->plugin, $this->Task->Fixture->plugin);
|
||||||
|
@ -523,7 +573,7 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
public function testBakeTest() {
|
public function testBakeTest() {
|
||||||
$this->Task->plugin = 'test_plugin';
|
$this->Task->plugin = 'test_plugin';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
$this->Task->Test->expectAt(0, 'bake', array('Model', 'Article'));
|
$this->Task->Test->expects($this->at(0))->method('bake')->with('Model', 'Article');
|
||||||
$this->Task->bakeTest('Article');
|
$this->Task->bakeTest('Article');
|
||||||
|
|
||||||
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
||||||
|
@ -562,11 +612,13 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
$model = new Model(array('ds' => 'test_suite', 'name' => 'CategoryThread'));
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'y');
|
|
||||||
|
$this->Task->expects($this->any())->method('in')
|
||||||
|
->will($this->onConsecutiveCalls('n', 'y', 'n', 'n', 'n'));
|
||||||
|
|
||||||
$result = $this->Task->confirmAssociations($model, $associations);
|
$result = $this->Task->confirmAssociations($model, $associations);
|
||||||
$this->assertTrue(empty($result['hasOne']));
|
$this->assertTrue(empty($result['hasOne']));
|
||||||
|
|
||||||
$this->Task->setReturnValue('in', 'n');
|
|
||||||
$result = $this->Task->confirmAssociations($model, $associations);
|
$result = $this->Task->confirmAssociations($model, $associations);
|
||||||
$this->assertTrue(empty($result['hasMany']));
|
$this->assertTrue(empty($result['hasMany']));
|
||||||
$this->assertTrue(empty($result['hasOne']));
|
$this->assertTrue(empty($result['hasOne']));
|
||||||
|
@ -578,16 +630,18 @@ class ModelTaskTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testInOptions() {
|
public function testInOptions() {
|
||||||
$options = array('one', 'two', 'three');
|
$this->_useMockedOut();
|
||||||
$this->Task->expectAt(0, 'out', array('1. one'));
|
|
||||||
$this->Task->expectAt(1, 'out', array('2. two'));
|
|
||||||
$this->Task->expectAt(2, 'out', array('3. three'));
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', 10);
|
|
||||||
|
|
||||||
$this->Task->expectAt(3, 'out', array('1. one'));
|
$options = array('one', 'two', 'three');
|
||||||
$this->Task->expectAt(4, 'out', array('2. two'));
|
$this->Task->expects($this->at(0))->method('out')->with('1. one');
|
||||||
$this->Task->expectAt(5, 'out', array('3. three'));
|
$this->Task->expects($this->at(1))->method('out')->with('2. two');
|
||||||
$this->Task->setReturnValueAt(1, 'in', 2);
|
$this->Task->expects($this->at(2))->method('out')->with('3. three');
|
||||||
|
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
|
||||||
|
|
||||||
|
$this->Task->expects($this->at(4))->method('out')->with('1. one');
|
||||||
|
$this->Task->expects($this->at(5))->method('out')->with('2. two');
|
||||||
|
$this->Task->expects($this->at(6))->method('out')->with('3. three');
|
||||||
|
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue(2));
|
||||||
$result = $this->Task->inOptions($options, 'Pick a number');
|
$result = $this->Task->inOptions($options, 'Pick a number');
|
||||||
$this->assertEqual($result, 1);
|
$this->assertEqual($result, 1);
|
||||||
}
|
}
|
||||||
|
@ -691,17 +745,12 @@ STRINGEND;
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testBakeWithPlugin() {
|
public function testBakeWithPlugin() {
|
||||||
$this->Task->plugin = 'ControllerTest';
|
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
|
||||||
$this->Task->bake('Article', array(), array());
|
|
||||||
|
|
||||||
$this->Task->plugin = 'controllerTest';
|
$this->Task->plugin = 'controllerTest';
|
||||||
|
|
||||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'models' . DS . 'article.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array(
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
$path, new PatternExpectation('/Article extends ControllerTestAppModel/')));
|
->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/Article extends ControllerTestAppModel/'));
|
||||||
|
|
||||||
$this->Task->bake('Article', array(), array());
|
$this->Task->bake('Article', array(), array());
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -718,8 +767,11 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array('article');
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article extends AppModel/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -727,27 +779,32 @@ STRINGEND;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that execute passes with different inflections of the same name.
|
* data provider for testExecuteWithNamedModelVariations
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testExecuteWithNamedModelVariations() {
|
static function nameVariations() {
|
||||||
|
return array(
|
||||||
|
array('Articles'), array('Article'), array('article'), array('articles')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that execute passes with different inflections of the same name.
|
||||||
|
*
|
||||||
|
* @dataProvider nameVariations
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testExecuteWithNamedModelVariations($name) {
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array($name);
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
$this->Task->execute();
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article extends AppModel/'));
|
||||||
|
|
||||||
$this->Task->args = array('Articles');
|
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
|
||||||
$this->Task->execute();
|
|
||||||
|
|
||||||
$this->Task->args = array('articles');
|
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class Article extends AppModel/')));
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -761,8 +818,11 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('article');
|
$this->Task->args = array('article');
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->setReturnValue('_checkUnitTest', 1);
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation("/'Comment' \=\> array\(/")));
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(1));
|
||||||
|
$this->Task->expects($this->at(0))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch("/'Comment' \=\> array\(/"));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -775,25 +835,30 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Task->Fixture->expectCallCount('bake', 5);
|
$this->Task->Fixture->expects($this->exactly(5))->method('bake');
|
||||||
$this->Task->Test->expectCallCount('bake', 5);
|
$this->Task->Test->expects($this->exactly(5))->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$filename = '/my/path/articles_tag.php';
|
$filename = '/my/path/articles_tag.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
$this->Task->expects($this->at(2))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesTag/'));
|
||||||
|
|
||||||
$filename = '/my/path/category_thread.php';
|
$filename = '/my/path/category_thread.php';
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment.php';
|
$filename = '/my/path/comment.php';
|
||||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Comment/'));
|
||||||
|
|
||||||
$filename = '/my/path/tag.php';
|
$filename = '/my/path/tag.php';
|
||||||
$this->Task->expectAt(4, 'createFile', array($filename, new PatternExpectation('/class Tag/')));
|
$this->Task->expects($this->at(5))
|
||||||
|
->method('createFile')->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Tag/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
|
@ -810,23 +875,27 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->args = array('all');
|
$this->Task->args = array('all');
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
$this->Task->skipTables = array('tags');
|
$this->Task->skipTables = array('tags');
|
||||||
|
|
||||||
$this->Task->Fixture->expectCallCount('bake', 4);
|
$this->Task->Fixture->expects($this->exactly(4))->method('bake');
|
||||||
$this->Task->Test->expectCallCount('bake', 4);
|
$this->Task->Test->expects($this->exactly(4))->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->at(1))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$filename = '/my/path/articles_tag.php';
|
$filename = '/my/path/articles_tag.php';
|
||||||
$this->Task->expectAt(1, 'createFile', array($filename, new PatternExpectation('/class ArticlesTag/')));
|
$this->Task->expects($this->at(2))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class ArticlesTag/'));
|
||||||
|
|
||||||
$filename = '/my/path/category_thread.php';
|
$filename = '/my/path/category_thread.php';
|
||||||
$this->Task->expectAt(2, 'createFile', array($filename, new PatternExpectation('/class CategoryThread/')));
|
$this->Task->expects($this->at(3))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
|
||||||
|
|
||||||
$filename = '/my/path/comment.php';
|
$filename = '/my/path/comment.php';
|
||||||
$this->Task->expectAt(3, 'createFile', array($filename, new PatternExpectation('/class Comment/')));
|
$this->Task->expects($this->at(4))->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Comment/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
|
@ -841,22 +910,27 @@ STRINGEND;
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
$this->Task->interactive = true;
|
$this->Task->interactive = true;
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
|
$this->Task->expects($this->any())->method('in')
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
|
->will($this->onConsecutiveCalls(
|
||||||
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
|
'1', // article
|
||||||
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
|
'n', // no validation
|
||||||
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
|
'y', // associations
|
||||||
$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
|
'y', // comment relation
|
||||||
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
|
'y', // user relation
|
||||||
$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
|
'y', // tag relation
|
||||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
'n', // additional assocs
|
||||||
|
'y' // looks good?
|
||||||
|
));
|
||||||
|
$this->Task->expects($this->once())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||||
|
|
||||||
$this->Task->Test->expectOnce('bake');
|
$this->Task->Test->expects($this->once())->method('bake');
|
||||||
$this->Task->Fixture->expectOnce('bake');
|
$this->Task->Fixture->expects($this->once())->method('bake');
|
||||||
|
|
||||||
$filename = '/my/path/article.php';
|
$filename = '/my/path/article.php';
|
||||||
$this->Task->expectOnce('createFile');
|
|
||||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
|
$this->Task->expects($this->once())->method('createFile')
|
||||||
|
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class Article/'));
|
||||||
|
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
|
|
||||||
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
$this->assertEqual(count(ClassRegistry::keys()), 0);
|
||||||
|
@ -872,11 +946,11 @@ STRINGEND;
|
||||||
$this->Task->connection = 'test_suite';
|
$this->Task->connection = 'test_suite';
|
||||||
$this->Task->path = '/my/path/';
|
$this->Task->path = '/my/path/';
|
||||||
|
|
||||||
$this->Task->expectOnce('_stop');
|
$this->Task->expects($this->once())->method('_stop');
|
||||||
$this->Task->expectOnce('err');
|
$this->Task->expects($this->once())->method('err');
|
||||||
|
|
||||||
$this->Task->setReturnValueAt(0, 'in', 'Foobar');
|
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('Foobar'));
|
||||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||||
$this->Task->execute();
|
$this->Task->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue