Skip to content

Commit

Permalink
Converting regular expression assertions to simple string contains, t…
Browse files Browse the repository at this point in the history
…hose perform faster and consume less memory
  • Loading branch information
lorenzo committed Sep 29, 2011
1 parent 27ab12d commit fbdb058
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions lib/Cake/Test/Case/Console/Command/AclShellTest.php
Expand Up @@ -77,13 +77,13 @@ public function testViewWithModelForeignKeyOutput() {

$this->Task->expects($this->at(0))->method('out')->with('Aro tree:');
$this->Task->expects($this->at(2))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[1\] ROOT/'));
->with($this->stringContains('[1] ROOT'));

$this->Task->expects($this->at(4))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[3\] Gandalf/'));
->with($this->stringContains('[3] Gandalf'));

$this->Task->expects($this->at(6))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[5\] MyModel\.2/'));
->with($this->stringContains('[5] MyModel.2'));

$this->Task->view();
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public function testGrant() {
public function testDeny() {
$this->Task->args = array('AuthUser.2', 'ROOT/Controller1', 'create');
$this->Task->expects($this->at(0))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/Permission denied/'), true);
->with($this->stringContains('Permission denied'), true);

$this->Task->deny();

Expand Down
18 changes: 9 additions & 9 deletions lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -314,7 +314,7 @@ public function testBakeWithPlugin() {
);
$this->Task->expects($this->at(3))->method('createFile')->with(
$path,
new PHPUnit_Framework_Constraint_PCREMatch('/ArticlesController extends ControllerTestAppController/')
$this->stringContains('ArticlesController extends ControllerTestAppController')
)->will($this->returnValue(true));

$this->Task->bake('Articles', '--actions--', array(), array(), array());
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testInteractive() {
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
$this->stringContains('class BakeArticlesController')
);
$this->Task->execute();
}
Expand Down Expand Up @@ -490,7 +490,7 @@ public function testInteractiveAdminMethodsNotInteractive() {
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
$this->stringContains('class BakeArticlesController')
)->will($this->returnValue(true));

$result = $this->Task->execute();
Expand Down Expand Up @@ -520,7 +520,7 @@ public function testExecuteIntoAll() {
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesController/')
$this->stringContains('class BakeArticlesController')
)->will($this->returnValue(true));

$this->Task->execute();
Expand All @@ -542,7 +542,7 @@ public function testExecuteWithController() {
$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename,
new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
$this->stringContains('$scaffold')
);

$this->Task->execute();
Expand Down Expand Up @@ -575,7 +575,7 @@ public function testExecuteWithControllerNameVariations($name) {

$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/')
$filename, $this->stringContains('$scaffold')
);
$this->Task->execute();
}
Expand All @@ -595,7 +595,7 @@ public function testExecuteWithPublicParam() {
$this->Task->params = array('public' => true);

$filename = '/my/path/BakeArticlesController.php';
$expected = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_PCREMatch('/\$scaffold/'));
$expected = new PHPUnit_Framework_Constraint_Not($this->stringContains('$scaffold'));
$this->Task->expects($this->once())->method('createFile')->with(
$filename, $expected
);
Expand All @@ -619,7 +619,7 @@ public function testExecuteWithControllerAndBoth() {

$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
$filename, $this->stringContains('admin_index')
);
$this->Task->execute();
}
Expand All @@ -641,7 +641,7 @@ public function testExecuteWithControllerAndAdmin() {

$filename = '/my/path/BakeArticlesController.php';
$this->Task->expects($this->once())->method('createFile')->with(
$filename, new PHPUnit_Framework_Constraint_PCREMatch('/admin_index/')
$filename, $this->stringContains('admin_index')
);
$this->Task->execute();
}
Expand Down
30 changes: 15 additions & 15 deletions lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php
Expand Up @@ -270,7 +270,7 @@ public function testInteractiveFieldValidationWithBogusResponse() {
->will($this->onConsecutiveCalls('999999', '21', 'n'));

$this->Task->expects($this->at(7))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/make a valid/'));
->with($this->stringContains('make a valid'));

$result = $this->Task->fieldValidation('text', array('type' => 'string', 'length' => 10, 'null' => false));
$expected = array('notempty' => 'notempty');
Expand Down Expand Up @@ -752,7 +752,7 @@ public function testBakeWithPlugin() {
CakePlugin::load('ControllerTest', array('path' => APP . 'Plugin' . DS . 'ControllerTest' . DS));
$path = APP . 'Plugin' . DS . 'ControllerTest' . DS . 'Model' . DS . 'BakeArticle.php';
$this->Task->expects($this->once())->method('createFile')
->with($path, new PHPUnit_Framework_Constraint_PCREMatch('/BakeArticle extends ControllerTestAppModel/'));
->with($path, $this->stringContains('BakeArticle extends ControllerTestAppModel'));

$result = $this->Task->bake('BakeArticle', array(), array());
$this->assertContains("App::uses('ControllerTestAppModel', 'ControllerTest.Model');", $result);
Expand All @@ -774,7 +774,7 @@ public function testExecuteWithNamedModel() {

$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 BakeArticle extends AppModel/'));
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));

$this->Task->execute();

Expand Down Expand Up @@ -808,7 +808,7 @@ public function testExecuteWithNamedModelVariations($name) {
$filename = '/my/path/BakeArticle.php';

$this->Task->expects($this->at(0))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticle extends AppModel/'));
->with($filename, $this->stringContains('class BakeArticle extends AppModel'));
$this->Task->execute();
}

Expand All @@ -825,7 +825,7 @@ public function testExecuteWithNamedModelHasManyCreated() {

$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("/'BakeComment' \=\> array\(/"));
->with($filename, $this->stringContains("'BakeComment' => array("));

$this->Task->execute();
}
Expand All @@ -851,23 +851,23 @@ public function testExecuteIntoAll() {

$filename = '/my/path/BakeArticle.php';
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticle/'));
->with($filename, $this->stringContains('class BakeArticle'));

$filename = '/my/path/BakeArticlesBakeTag.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesBakeTag/'));
->with($filename, $this->stringContains('class BakeArticlesBakeTag'));

$filename = '/my/path/BakeComment.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeComment/'));
->with($filename, $this->stringContains('class BakeComment'));

$filename = '/my/path/BakeTag.php';
$this->Task->expects($this->at(4))
->method('createFile')->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeTag/'));
->method('createFile')->with($filename, $this->stringContains('class BakeTag'));

$filename = '/my/path/CategoryThread.php';
$this->Task->expects($this->at(5))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
->with($filename, $this->stringContains('class CategoryThread'));

$this->Task->execute();

Expand Down Expand Up @@ -897,19 +897,19 @@ public function testSkipTablesAndAll() {

$filename = '/my/path/BakeArticle.php';
$this->Task->expects($this->at(1))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticle/'));
->with($filename, $this->stringContains('class BakeArticle'));

$filename = '/my/path/BakeArticlesBakeTag.php';
$this->Task->expects($this->at(2))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticlesBakeTag/'));
->with($filename, $this->stringContains('class BakeArticlesBakeTag'));

$filename = '/my/path/BakeComment.php';
$this->Task->expects($this->at(3))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeComment/'));
->with($filename, $this->stringContains('class BakeComment'));

$filename = '/my/path/CategoryThread.php';
$this->Task->expects($this->at(4))->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class CategoryThread/'));
->with($filename, $this->stringContains('class CategoryThread'));

$this->Task->execute();
}
Expand Down Expand Up @@ -948,7 +948,7 @@ public function testExecuteIntoInteractive() {
$filename = '/my/path/BakeArticle.php';

$this->Task->expects($this->once())->method('createFile')
->with($filename, new PHPUnit_Framework_Constraint_PCREMatch('/class BakeArticle/'));
->with($filename, $this->stringContains('class BakeArticle'));

$this->Task->execute();

Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php
Expand Up @@ -600,7 +600,7 @@ public function testExecuteWithOneArg() {
$this->Task->expects($this->once())->method('createFile')
->with(
new PHPUnit_Framework_Constraint_IsAnything(),
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
$this->stringContains('class TestTaskTagTestCase extends CakeTestCase')
);
$this->Task->execute();
}
Expand All @@ -616,7 +616,7 @@ public function testExecuteWithTwoArgs() {
$this->Task->expects($this->once())->method('createFile')
->with(
new PHPUnit_Framework_Constraint_IsAnything(),
new PHPUnit_Framework_Constraint_PCREMatch('/class TestTaskTagTestCase extends CakeTestCase/')
$this->stringContains('class TestTaskTagTestCase extends CakeTestCase')
);
$this->Task->expects($this->any())->method('isLoadableClass')->will($this->returnValue(true));
$this->Task->execute();
Expand Down
28 changes: 14 additions & 14 deletions lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php
Expand Up @@ -322,7 +322,7 @@ public function testBakeView() {
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/View Task Articles/')
$this->stringContains('View Task Articles')
);

$this->Task->bake('view', true);
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testBakeIndex() {
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/\$viewTaskComment\[\'Article\'\]\[\'title\'\]/')
$this->stringContains("\$viewTaskComment['Article']['title']")
);
$this->Task->bake('index', true);
}
Expand Down Expand Up @@ -403,17 +403,17 @@ public function testBakeActions() {
$this->Task->expects($this->at(0))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/View Task Comments/')
$this->stringContains('View Task Comments')
);
$this->Task->expects($this->at(1))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
$this->stringContains('Edit View Task Comment')
);
$this->Task->expects($this->at(2))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);

$this->Task->bakeActions(array('view', 'edit', 'index'), array());
Expand Down Expand Up @@ -606,25 +606,25 @@ public function testExecuteInteractive() {
$this->Task->expects($this->at(3))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'index.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);

$this->Task->expects($this->at(4))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'view.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);

$this->Task->expects($this->at(5))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'add.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/Add View Task Comment/')
$this->stringContains('Add View Task Comment')
);

$this->Task->expects($this->at(6))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'edit.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
$this->stringContains('Edit View Task Comment')
);

$this->Task->expects($this->exactly(4))->method('createFile');
Expand All @@ -644,7 +644,7 @@ public function testExecuteWithAlternateTemplates() {
$this->Task->expects($this->once())->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'list.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);
$this->Task->execute();
}
Expand All @@ -671,25 +671,25 @@ public function testExecuteInteractiveWithAdmin() {
$this->Task->expects($this->at(3))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_index.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);

$this->Task->expects($this->at(4))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_view.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/ViewTaskComment/')
$this->stringContains('ViewTaskComment')
);

$this->Task->expects($this->at(5))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_add.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/Add View Task Comment/')
$this->stringContains('Add View Task Comment')
);

$this->Task->expects($this->at(6))->method('createFile')
->with(
TMP . 'ViewTaskComments' . DS . 'admin_edit.ctp',
new PHPUnit_Framework_Constraint_PCREMatch('/Edit View Task Comment/')
$this->stringContains('Edit View Task Comment')
);

$this->Task->expects($this->exactly(4))->method('createFile');
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Console/Command/TestsuiteShellTest.php
Expand Up @@ -72,9 +72,9 @@ public function testAvailableCoreCategory() {
$this->Shell->args = array('core');
$this->Shell->expects($this->at(0))->method('out')->with('Core Test Cases:');
$this->Shell->expects($this->at(1))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[1\].*/'));
->with($this->stringContains('[1]'));
$this->Shell->expects($this->at(2))->method('out')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/\[2\].*/'));
->with($this->stringContains('[2]'));

$this->Shell->expects($this->once())->method('in')
->with(__d('cake_console', 'What test case would you like to run?'), null, 'q')
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -1055,10 +1055,10 @@ public function testGenerateInnerJoinAssociationQuery() {
->will($this->returnValue($test));
$test->expects($this->at(0))->method('execute')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/`TestModel9` LEFT JOIN `test_model8`/'));
->with($this->stringContains('`TestModel9` LEFT JOIN `test_model8`'));
$test->expects($this->at(1))->method('execute')
->with(new PHPUnit_Framework_Constraint_PCREMatch('/`TestModel9` INNER JOIN `test_model8`/'));
->with($this->stringContains('TestModel9` INNER JOIN `test_model8`'));
$test->read($this->Model, array('recursive' => 1));
$this->Model->belongsTo['TestModel8']['type'] = 'INNER';
Expand Down

0 comments on commit fbdb058

Please sign in to comment.