mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-05 19:12:42 +00:00
Starting to convert controller task test to phpunit.
This commit is contained in:
parent
66699df9a0
commit
08bcf55b8d
1 changed files with 81 additions and 90 deletions
|
@ -38,27 +38,6 @@ require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'model.php';
|
|||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'template.php';
|
||||
require_once CAKE . 'console' . DS . 'libs' . DS . 'tasks' . DS . 'test.php';
|
||||
|
||||
Mock::generatePartial(
|
||||
'ShellDispatcher', 'TestControllerTaskMockShellDispatcher',
|
||||
array('getInput', 'stdout', 'stderr', '_stop', '_initEnvironment')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ControllerTask', 'MockControllerTask',
|
||||
array('in', 'hr', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ModelTask', 'ControllerMockModelTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest')
|
||||
);
|
||||
|
||||
Mock::generatePartial(
|
||||
'ProjectTask', 'ControllerMockProjectTask',
|
||||
array('in', 'out', 'err', 'createFile', '_stop', '_checkUnitTest', 'getPrefix')
|
||||
);
|
||||
|
||||
Mock::generate('TestTask', 'ControllerMockTestTask');
|
||||
|
||||
$imported = App::import('Model', 'Article');
|
||||
$imported = $imported || App::import('Model', 'Comment');
|
||||
|
@ -98,16 +77,21 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
* @return void
|
||||
*/
|
||||
public function startTest() {
|
||||
$this->Dispatcher =& new TestControllerTaskMockShellDispatcher();
|
||||
$this->Task =& new MockControllerTask($this->Dispatcher);
|
||||
$this->Dispatcher = $this->getMock('ShellDispatcher', array(
|
||||
'getInput', 'stdout', 'stderr', '_stop', '_initEnvironment'
|
||||
));
|
||||
$this->Task = $this->getMock('ControllerTask',
|
||||
array('in', 'out', 'err', 'hr', 'createFile', '_stop', '_checkUnitTest'),
|
||||
array(&$this->Dispatcher)
|
||||
);
|
||||
$this->Task->name = 'ControllerTask';
|
||||
$this->Task->Dispatch =& $this->Dispatcher;
|
||||
$this->Task->Dispatch->shellPaths = App::path('shells');
|
||||
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
|
||||
$this->Task->Template->params['theme'] = 'default';
|
||||
$this->Task->Model =& new ControllerMockModelTask($this->Task->Dispatch);
|
||||
$this->Task->Project =& new ControllerMockProjectTask($this->Task->Dispatch);
|
||||
$this->Task->Test =& new ControllerMockTestTask();
|
||||
|
||||
$this->Task->Model = $this->getMock('ModelTask', array(), array(&$this->Dispatcher));
|
||||
$this->Task->Project = $this->getMock('ProjectTask', array(), array(&$this->Dispatcher));
|
||||
$this->Task->Test = $this->getMock('TestTask', array(), array(&$this->Dispatcher));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -128,20 +112,20 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
public function testListAll() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->expectAt(1, 'out', array('1. Articles'));
|
||||
$this->Task->expectAt(2, 'out', array('2. ArticlesTags'));
|
||||
$this->Task->expectAt(3, 'out', array('3. Comments'));
|
||||
$this->Task->expectAt(4, 'out', array('4. Tags'));
|
||||
$this->Task->expects($this->at(1))->method('out')->with('1. Articles');
|
||||
$this->Task->expects($this->at(2))->method('out')->with('2. ArticlesTags');
|
||||
$this->Task->expects($this->at(3))->method('out')->with('3. Comments');
|
||||
$this->Task->expects($this->at(4))->method('out')->with('4. Tags');
|
||||
|
||||
$this->Task->expects($this->at(6))->method('out')->with('1. Articles');
|
||||
$this->Task->expects($this->at(7))->method('out')->with('2. ArticlesTags');
|
||||
$this->Task->expects($this->at(8))->method('out')->with('4. Comments');
|
||||
$this->Task->expects($this->at(9))->method('out')->with('5. Tags');
|
||||
|
||||
$expected = array('Articles', 'ArticlesTags', 'Comments', 'Tags');
|
||||
$result = $this->Task->listAll('test_suite');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->expectAt(6, 'out', array('1. Articles'));
|
||||
$this->Task->expectAt(7, 'out', array('2. ArticlesTags'));
|
||||
$this->Task->expectAt(8, 'out', array('4. Comments'));
|
||||
$this->Task->expectAt(9, 'out', array('5. Tags'));
|
||||
|
||||
$this->Task->interactive = false;
|
||||
$result = $this->Task->listAll();
|
||||
|
||||
|
@ -154,25 +138,25 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetName() {
|
||||
public function xxtestGetName() {
|
||||
$this->Task->interactive = true;
|
||||
$this->Task->setReturnValue('in', 1);
|
||||
$this->Task->expects($this->any())->method('in')->will($this->returnValue(1));
|
||||
|
||||
$this->Task->setReturnValueAt(0, 'in', 'q');
|
||||
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('q'));
|
||||
$this->Task->expectOnce('_stop');
|
||||
$this->Task->getName('test_suite');
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 1);
|
||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(1));
|
||||
$result = $this->Task->getName('test_suite');
|
||||
$expected = 'Articles';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(2, 'in', 3);
|
||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(3));
|
||||
$result = $this->Task->getName('test_suite');
|
||||
$expected = 'Comments';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(3, 'in', 10);
|
||||
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue(10));
|
||||
$result = $this->Task->getName('test_suite');
|
||||
$this->Task->expectOnce('err');
|
||||
}
|
||||
|
@ -182,19 +166,19 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDoHelpers() {
|
||||
$this->Task->setReturnValue('in', 'n');
|
||||
public function xxtestDoHelpers() {
|
||||
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
||||
$result = $this->Task->doHelpers();
|
||||
$this->assertEqual($result, array());
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', ' Javascript, Ajax, CustomOne ');
|
||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne '));
|
||||
$result = $this->Task->doHelpers();
|
||||
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(3, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(4, 'in', ' Javascript, Ajax, CustomOne, , ');
|
||||
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y'));
|
||||
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
|
||||
$result = $this->Task->doHelpers();
|
||||
$expected = array('Javascript', 'Ajax', 'CustomOne');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -205,19 +189,22 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDoComponents() {
|
||||
$this->Task->setReturnValue('in', 'n');
|
||||
public function xxtestDoComponents() {
|
||||
$this->Task->expects($this->any())->method('in')->will($this->returnValue('n'));
|
||||
|
||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y'));
|
||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue(' RequestHandler, Security '));
|
||||
|
||||
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y'));
|
||||
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue(' RequestHandler, Security, , '));
|
||||
|
||||
$result = $this->Task->doComponents();
|
||||
$this->assertEqual($result, array());
|
||||
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(2, 'in', ' RequestHandler, Security ');
|
||||
$result = $this->Task->doComponents();
|
||||
$expected = array('RequestHandler', 'Security');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$this->Task->setReturnValueAt(3, 'in', 'y');
|
||||
$this->Task->setReturnValueAt(4, 'in', ' RequestHandler, Security, , ');
|
||||
$result = $this->Task->doComponents();
|
||||
$expected = array('RequestHandler', 'Security');
|
||||
$this->assertEqual($result, $expected);
|
||||
|
@ -228,16 +215,16 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testConfirmController() {
|
||||
public function xxtestConfirmController() {
|
||||
$controller = 'Posts';
|
||||
$scaffold = false;
|
||||
$helpers = array('Ajax', 'Time');
|
||||
$components = array('Acl', 'Auth');
|
||||
$uses = array('Comment', 'User');
|
||||
|
||||
$this->Task->expectAt(2, 'out', array("Controller Name:\n\t$controller"));
|
||||
$this->Task->expectAt(3, 'out', array("Helpers:\n\tAjax, Time"));
|
||||
$this->Task->expectAt(4, 'out', array("Components:\n\tAcl, Auth"));
|
||||
$this->Task->expects($this->at(2))->method('out')->with("Controller Name:\n\t$controller");
|
||||
$this->Task->expects($this->at(3))->method('out')->with("Helpers:\n\tAjax, Time");
|
||||
$this->Task->expects($this->at(4))->method('out')->with("Components:\n\tAcl, Auth");
|
||||
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
|
||||
}
|
||||
|
||||
|
@ -246,10 +233,10 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBake() {
|
||||
public function xxtestBake() {
|
||||
$helpers = array('Ajax', 'Time');
|
||||
$components = array('Acl', 'Auth');
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
|
||||
|
||||
$result = $this->Task->bake('Articles', '--actions--', $helpers, $components);
|
||||
$this->assertPattern('/class ArticlesController extends AppController/', $result);
|
||||
|
@ -275,20 +262,24 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBakeWithPlugin() {
|
||||
public function xxtestBakeWithPlugin() {
|
||||
$this->Task->plugin = 'ControllerTest';
|
||||
$helpers = array('Ajax', 'Time');
|
||||
$components = array('Acl', 'Auth');
|
||||
$uses = array('Comment', 'User');
|
||||
|
||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($path, '*'));
|
||||
|
||||
$this->Task->expects($this->at(0))->method('createFile')->with($path, '*');
|
||||
$this->Task->expects($this->at(1))->method('createFile')->with(
|
||||
$path,
|
||||
new PHPUnit_Framework_Constraint_PCREMatch('/ArticlesController extends ControllerTestAppController/')
|
||||
);
|
||||
|
||||
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
||||
|
||||
$this->Task->plugin = 'controllerTest';
|
||||
$path = APP . 'plugins' . DS . 'controller_test' . DS . 'controllers' . DS . 'articles_controller.php';
|
||||
$this->Task->expectAt(1, 'createFile', array(
|
||||
$path, new PatternExpectation('/ArticlesController extends ControllerTestAppController/')));
|
||||
$this->Task->bake('Articles', '--actions--', array(), array(), array());
|
||||
}
|
||||
|
||||
|
@ -297,7 +288,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBakeActionsUsingSessions() {
|
||||
public function xxtestBakeActionsUsingSessions() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Testing bakeActions requires Article, Comment & Tag Model to be undefined. %s');
|
||||
if ($skip) {
|
||||
|
@ -339,7 +330,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBakeActionsWithNoSessions() {
|
||||
public function xxtestBakeActionsWithNoSessions() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Testing bakeActions requires Article, Tag, Comment Models to be undefined. %s');
|
||||
if ($skip) {
|
||||
|
@ -374,12 +365,12 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testBakeTest() {
|
||||
public function xxtestBakeTest() {
|
||||
$this->Task->plugin = 'ControllerTest';
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->interactive = false;
|
||||
|
||||
$this->Task->Test->expectOnce('bake', array('Controller', 'Articles'));
|
||||
$this->Task->Test->expects($this->once())->method('bake')->with('Controller', 'Articles');
|
||||
$this->Task->bakeTest('Articles');
|
||||
|
||||
$this->assertEqual($this->Task->plugin, $this->Task->Test->plugin);
|
||||
|
@ -392,23 +383,23 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testInteractive() {
|
||||
public function xxtestInteractive() {
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path';
|
||||
$this->Task->setReturnValue('in', '1');
|
||||
$this->Task->setReturnValueAt(1, 'in', 'y'); // build interactive
|
||||
$this->Task->setReturnValueAt(2, 'in', 'n'); // build no scaffolds
|
||||
$this->Task->setReturnValueAt(3, 'in', 'y'); // build normal methods
|
||||
$this->Task->setReturnValueAt(4, 'in', 'n'); // build admin methods
|
||||
$this->Task->setReturnValueAt(5, 'in', 'n'); // helpers?
|
||||
$this->Task->setReturnValueAt(6, 'in', 'n'); // components?
|
||||
$this->Task->setReturnValueAt(7, 'in', 'y'); // use sessions
|
||||
$this->Task->setReturnValueAt(8, 'in', 'y'); // looks good
|
||||
$this->Task->expects($this->any())->method('in')->will($this->returnValue('1'));
|
||||
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue('y')); // build interactive
|
||||
$this->Task->expects($this->at(2))->method('in')->will($this->returnValue('n')); // build no scaffolds
|
||||
$this->Task->expects($this->at(3))->method('in')->will($this->returnValue('y')); // build normal methods
|
||||
$this->Task->expects($this->at(4))->method('in')->will($this->returnValue('n')); // build admin methods
|
||||
$this->Task->expects($this->at(5))->method('in')->will($this->returnValue('n')); // helpers?
|
||||
$this->Task->expects($this->at(6))->method('in')->will($this->returnValue('n')); // components?
|
||||
$this->Task->expects($this->at(7))->method('in')->will($this->returnValue('y')); // use sessions
|
||||
$this->Task->expects($this->at(8))->method('in')->will($this->returnValue('y')); // looks good
|
||||
|
||||
$this->Task->execute();
|
||||
|
||||
$filename = '/my/path/articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
||||
$this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -416,7 +407,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteIntoAll() {
|
||||
public function xxtestExecuteIntoAll() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute into all could not be run as an Article, Tag or Comment model was already loaded. %s');
|
||||
if ($skip) {
|
||||
|
@ -426,12 +417,12 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('all');
|
||||
|
||||
$this->Task->setReturnValue('createFile', true);
|
||||
$this->Task->setReturnValue('_checkUnitTest', true);
|
||||
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));
|
||||
$this->Task->expects($this->any())->method('_checkUnitTest')->will($this->returnValue(true));
|
||||
$this->Task->Test->expectCallCount('bake', 1);
|
||||
|
||||
$filename = '/my/path/articles_controller.php';
|
||||
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class ArticlesController/')));
|
||||
$this->Task->expects($this->at(0))->method('createFile')->with($filename, new PatternExpectation('/class ArticlesController/'));
|
||||
|
||||
$this->Task->execute();
|
||||
}
|
||||
|
@ -441,7 +432,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteWithController() {
|
||||
public function xxtestExecuteWithController() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||
if ($skip) {
|
||||
|
@ -464,7 +455,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteWithControllerNameVariations() {
|
||||
public function xxtestExecuteWithControllerNameVariations() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||
if ($skip) {
|
||||
|
@ -515,7 +506,7 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteWithPublicParam() {
|
||||
public function xxtestExecuteWithPublicParam() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||
if ($skip) {
|
||||
|
@ -538,13 +529,13 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteWithControllerAndBoth() {
|
||||
public function xxtestExecuteWithControllerAndBoth() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||
if ($skip) {
|
||||
return;
|
||||
}
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('Articles', 'public', 'admin');
|
||||
|
@ -562,13 +553,13 @@ class ControllerTaskTest extends CakeTestCase {
|
|||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecuteWithControllerAndAdmin() {
|
||||
public function xxtestExecuteWithControllerAndAdmin() {
|
||||
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
|
||||
'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
|
||||
if ($skip) {
|
||||
return;
|
||||
}
|
||||
$this->Task->Project->setReturnValue('getPrefix', 'admin_');
|
||||
$this->Task->Project->expects($this->any())->method('getPrefix')->will($this->returnValue('admin_'));
|
||||
$this->Task->connection = 'test_suite';
|
||||
$this->Task->path = '/my/path/';
|
||||
$this->Task->args = array('Articles', 'admin');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue