Browse Source

Converting regular expression assertions to simple string contains, those perform faster and consume less memory

Jose Lorenzo Rodriguez 14 years ago
parent
commit
fbdb058441

+ 4 - 4
lib/Cake/Test/Case/Console/Command/AclShellTest.php

@@ -77,13 +77,13 @@ class AclShellTest extends CakeTestCase {
 
 		$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();
 	}
@@ -216,7 +216,7 @@ class AclShellTest extends CakeTestCase {
 	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();
 

+ 9 - 9
lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php

@@ -314,7 +314,7 @@ class ControllerTaskTest extends CakeTestCase {
 		);
 		$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());
@@ -450,7 +450,7 @@ class ControllerTaskTest extends CakeTestCase {
 		$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();
 	}
@@ -490,7 +490,7 @@ class ControllerTaskTest extends CakeTestCase {
 		$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();
@@ -520,7 +520,7 @@ class ControllerTaskTest extends CakeTestCase {
 		$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();
@@ -542,7 +542,7 @@ class ControllerTaskTest extends CakeTestCase {
 		$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();
@@ -575,7 +575,7 @@ class ControllerTaskTest extends CakeTestCase {
 
 		$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();
 	}
@@ -595,7 +595,7 @@ class ControllerTaskTest extends CakeTestCase {
 		$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
 		);
@@ -619,7 +619,7 @@ class ControllerTaskTest extends CakeTestCase {
 
 		$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();
 	}
@@ -641,7 +641,7 @@ class ControllerTaskTest extends CakeTestCase {
 
 		$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();
 	}

+ 15 - 15
lib/Cake/Test/Case/Console/Command/Task/ModelTaskTest.php

@@ -270,7 +270,7 @@ class ModelTaskTest extends CakeTestCase {
 			->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');
@@ -752,7 +752,7 @@ STRINGEND;
 		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);
@@ -774,7 +774,7 @@ STRINGEND;
 
 		$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();
 
@@ -808,7 +808,7 @@ STRINGEND;
 		$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();
 	}
 
@@ -825,7 +825,7 @@ STRINGEND;
 
 		$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();
 	}
@@ -851,23 +851,23 @@ STRINGEND;
 
 		$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();
 
@@ -897,19 +897,19 @@ STRINGEND;
 
 		$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();
 	}
@@ -948,7 +948,7 @@ STRINGEND;
 		$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();
 

+ 2 - 2
lib/Cake/Test/Case/Console/Command/Task/TestTaskTest.php

@@ -600,7 +600,7 @@ class TestTaskTest extends CakeTestCase {
 		$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();
 	}
@@ -616,7 +616,7 @@ class TestTaskTest extends CakeTestCase {
 		$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();

+ 14 - 14
lib/Cake/Test/Case/Console/Command/Task/ViewTaskTest.php

@@ -322,7 +322,7 @@ class ViewTaskTest extends CakeTestCase {
 		$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);
@@ -355,7 +355,7 @@ class ViewTaskTest extends CakeTestCase {
 		$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);
 	}
@@ -403,17 +403,17 @@ class ViewTaskTest extends CakeTestCase {
 		$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());
@@ -606,25 +606,25 @@ class ViewTaskTest extends CakeTestCase {
 		$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');
@@ -644,7 +644,7 @@ class ViewTaskTest extends CakeTestCase {
 		$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();
 	}
@@ -671,25 +671,25 @@ class ViewTaskTest extends CakeTestCase {
 		$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');

+ 2 - 2
lib/Cake/Test/Case/Console/Command/TestsuiteShellTest.php

@@ -72,9 +72,9 @@ class TestsuiteShellTest extends CakeTestCase {
 		$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')

+ 2 - 2
lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php

@@ -1055,10 +1055,10 @@ class MysqlTest extends CakeTestCase {
 			->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';