Skip to content

Commit

Permalink
Fixing bake and bake related task test cases for PHP4.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Aug 2, 2009
1 parent 593bec8 commit 48a483e
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cake/console/libs/tasks/fixture.php
Expand Up @@ -390,7 +390,7 @@ function _getRecordsFromTable($modelName, $useTable = null) {
'conditions' => $condition,
'recursive' => -1
));
$db =& $modelObject->getDataSource();
$db =& ConnectionManager::getDataSource($modelObject->useDbConfig);
$schema = $modelObject->schema();
$out = array();
foreach ($records as $record) {
Expand Down
2 changes: 1 addition & 1 deletion cake/console/libs/tasks/test.php
Expand Up @@ -268,7 +268,7 @@ function getTestableMethods($className) {
$thisMethods = array_diff($classMethods, $parentMethods);
$out = array();
foreach ($thisMethods as $method) {
if (substr($method, 0, 1) != '_') {
if (substr($method, 0, 1) != '_' && $method != strtolower($className)) {
$out[] = $method;
}
}
Expand Down
2 changes: 1 addition & 1 deletion cake/console/libs/tasks/view.php
Expand Up @@ -166,7 +166,7 @@ function _methodsToBake() {
unset($methods[$i]);
}
}
if ($method[0] === '_') {
if ($method[0] === '_' || $method == strtolower($this->controllerName . 'Controller')) {
unset($methods[$i]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/controller.test.php
Expand Up @@ -100,7 +100,7 @@ class ControllerTaskTest extends CakeTestCase {
function startTest() {
$this->Dispatcher =& new TestControllerTaskMockShellDispatcher();
$this->Task =& new MockControllerTask($this->Dispatcher);
$this->Task->Dispatch =& new $this->Dispatcher;
$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';
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/db_config.test.php
Expand Up @@ -82,7 +82,7 @@ class DbConfigTaskTest extends CakeTestCase {
function startTest() {
$this->Dispatcher =& new TestDbConfigTaskMockShellDispatcher();
$this->Task =& new MockDbConfigTask($this->Dispatcher);
$this->Task->Dispatch =& new $this->Dispatcher;
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Dispatch->shellPaths = App::path('shells');

$this->Task->params['working'] = rtrim(APP, '/');
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/fixture.test.php
Expand Up @@ -73,7 +73,7 @@ function startTest() {
$this->Dispatcher =& new TestFixtureTaskMockShellDispatcher();
$this->Task =& new MockFixtureTask();
$this->Task->Model =& new MockFixtureModelTask();
$this->Task->Dispatch = new $this->Dispatcher;
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template->initialize();
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -80,7 +80,7 @@ class ModelTaskTest extends CakeTestCase {
function startTest() {
$this->Dispatcher =& new TestModelTaskMockShellDispatcher();
$this->Task =& new MockModelTask($this->Dispatcher);
$this->Task->Dispatch =& new $this->Dispatcher;
$this->Task->Dispatch =& $this->Dispatcher;
$this->Task->Dispatch->shellPaths = App::path('shells');
$this->Task->Template =& new TemplateTask($this->Task->Dispatch);
$this->Task->Fixture =& new MockModelTaskFixtureTask();
Expand Down
21 changes: 14 additions & 7 deletions cake/tests/cases/console/libs/tasks/test.test.php
Expand Up @@ -182,8 +182,8 @@ function testFilePathGeneration() {
**/
function testMethodIntrospection() {
$result = $this->Task->getTestableMethods('TestTaskArticle');
$expected = array('doSomething', 'doSomethingElse');
$this->assertEqual($result, $expected);
$expected = array('dosomething', 'dosomethingelse');
$this->assertEqual(array_map('strtolower', $result), $expected);
}

/**
Expand Down Expand Up @@ -310,7 +310,8 @@ function testGetRealClassname() {
}

/**
* test baking files.
* test baking files. The conditionally run tests are known to fail in PHP4
* as PHP4 classnames are all lower case, breaking the plugin path inflection.
*
* @return void
**/
Expand All @@ -329,17 +330,21 @@ function testBakeModelTest() {
$this->assertPattern('/function endTest\(\)/', $result);
$this->assertPattern('/unset\(\$this->TestTaskArticle\)/', $result);

$this->assertPattern('/function testDoSomething\(\)/', $result);
$this->assertPattern('/function testDoSomethingElse\(\)/', $result);
$this->assertPattern('/function testDoSomething\(\)/i', $result);
$this->assertPattern('/function testDoSomethingElse\(\)/i', $result);

$this->assertPattern("/'app\.test_task_article'/", $result);
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
if (PHP5) {
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
}
$this->assertPattern("/'app\.test_task_tag'/", $result);
$this->assertPattern("/'app\.articles_tag'/", $result);
}

/**
* test baking controller test files, ensure that the stub class is generated.
* Conditional assertion is known to fail on PHP4 as classnames are all lower case
* causing issues with inflection of path name from classname.
*
* @return void
**/
Expand All @@ -363,7 +368,9 @@ function testBakeControllerTest() {
$this->assertPattern('/unset\(\$this->TestTaskComments\)/', $result);

$this->assertPattern("/'app\.test_task_article'/", $result);
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
if (PHP5) {
$this->assertPattern("/'plugin\.test_task\.test_task_comment'/", $result);
}
$this->assertPattern("/'app\.test_task_tag'/", $result);
$this->assertPattern("/'app\.articles_tag'/", $result);
}
Expand Down

0 comments on commit 48a483e

Please sign in to comment.