Browse Source

use _normalizePath()

euromark 12 years ago
parent
commit
cc1a6e09a0

+ 10 - 0
src/TestSuite/TestCase.php

@@ -469,6 +469,16 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
 		return $string;
 	}
 
+/**
+ * Normalize a path for comparison.
+ *
+ * @param string $path Path separated by "/" slash.
+ * @return string Normalized path separated by DS.
+ */
+	protected function _normalizePath($path) {
+		return str_replace('/', DS, $path);
+	}
+
 // @codingStandardsIgnoreStart
 
 /**

+ 1 - 1
tests/TestCase/Console/Command/Task/ControllerTaskTest.php

@@ -189,7 +189,7 @@ class ControllerTaskTest extends TestCase {
 	public function testBakePrefixed() {
 		$this->Task->params['prefix'] = 'Admin';
 
-		$filename = str_replace('/', DS, '/my/path/Admin/BakeArticlesController.php');
+		$filename = $this->_normalizePath('/my/path/Admin/BakeArticlesController.php');
 		$this->Task->expects($this->at(1))
 			->method('createFile')
 			->with($filename, $this->anything());

+ 1 - 1
tests/TestCase/Console/Command/Task/FixtureTaskTest.php

@@ -396,7 +396,7 @@ class FixtureTaskTest extends TestCase {
  */
 	public function testGeneratePluginFixtureFile() {
 		$this->Task->connection = 'test';
-		$this->Task->path = str_replace('/', DS, '/my/path/');
+		$this->Task->path = $this->_normalizePath('/my/path/');
 		$this->Task->plugin = 'TestPlugin';
 		$filename = TEST_APP . 'Plugin/TestPlugin/Test/Fixture/ArticleFixture.php';
 		$filename = str_replace('/', DS, $filename);

+ 23 - 23
tests/TestCase/Console/Command/Task/ModelTaskTest.php

@@ -747,15 +747,15 @@ class ModelTaskTest extends TestCase {
  */
 	public function testExecuteWithNamedModel() {
 		$this->Task->connection = 'test';
-		$this->Task->path = str_replace('/', DS, '/my/path/');
+		$this->Task->path = $this->_normalizePath('/my/path/');
 		$this->Task->args = ['BakeArticles'];
 
-		$tableFile = str_replace('/', DS, '/my/path/Table/BakeArticlesTable.php');
+		$tableFile = $this->_normalizePath('/my/path/Table/BakeArticlesTable.php');
 		$this->Task->expects($this->at(0))
 			->method('createFile')
 			->with($tableFile, $this->stringContains('class BakeArticlesTable extends Table'));
 
-		$entityFile = str_replace('/', DS, '/my/path/Entity/BakeArticle.php');
+		$entityFile = $this->_normalizePath('/my/path/Entity/BakeArticle.php');
 		$this->Task->expects($this->at(1))
 			->method('createFile')
 			->with($entityFile, $this->stringContains('class BakeArticle extends Entity'));
@@ -782,10 +782,10 @@ class ModelTaskTest extends TestCase {
  */
 	public function testExecuteWithNamedModelVariations($name) {
 		$this->Task->connection = 'test';
-		$this->Task->path = str_replace('/', DS, '/my/path/');
+		$this->Task->path = $this->_normalizePath('/my/path/');
 
 		$this->Task->args = array($name);
-		$filename = str_replace('/', DS, '/my/path/Table/BakeArticlesTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/BakeArticlesTable.php');
 
 		$this->Task->expects($this->at(0))
 			->method('createFile')
@@ -805,7 +805,7 @@ class ModelTaskTest extends TestCase {
 		}
 
 		$this->Task->connection = 'test';
-		$this->Task->path = str_replace('/', DS, '/my/path/');
+		$this->Task->path = $this->_normalizePath('/my/path/');
 		$this->Task->args = ['all'];
 
 		$this->Task->Fixture->expects($this->exactly($count))
@@ -813,52 +813,52 @@ class ModelTaskTest extends TestCase {
 		$this->Task->Test->expects($this->exactly($count))
 			->method('bake');
 
-		$filename = str_replace('/', DS, '/my/path/Table/BakeArticlesTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/BakeArticlesTable.php');
 		$this->Task->expects($this->at(0))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeArticlesTable extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeArticle.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeArticle.php');
 		$this->Task->expects($this->at(1))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeArticle extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Table/BakeArticlesBakeTagsTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/BakeArticlesBakeTagsTable.php');
 		$this->Task->expects($this->at(2))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeArticlesBakeTagsTable extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeArticlesBakeTag.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeArticlesBakeTag.php');
 		$this->Task->expects($this->at(3))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeArticlesBakeTag extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Table/BakeCommentsTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/BakeCommentsTable.php');
 		$this->Task->expects($this->at(4))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeCommentsTable extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeComment.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeComment.php');
 		$this->Task->expects($this->at(5))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeComment extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Table/BakeTagsTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/BakeTagsTable.php');
 		$this->Task->expects($this->at(6))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeTagsTable extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeTag.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeTag.php');
 		$this->Task->expects($this->at(7))
 			->method('createFile')
 			->with($filename, $this->stringContains('class BakeTag extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Table/CategoryThreadsTable.php');
+		$filename = $this->_normalizePath('/my/path/Table/CategoryThreadsTable.php');
 		$this->Task->expects($this->at(8))
 			->method('createFile')
 			->with($filename, $this->stringContains('class CategoryThreadsTable extends'));
 
-		$filename = str_replace('/', DS, '/my/path/Entity/CategoryThread.php');
+		$filename = $this->_normalizePath('/my/path/Entity/CategoryThread.php');
 		$this->Task->expects($this->at(9))
 			->method('createFile')
 			->with($filename, $this->stringContains('class CategoryThread extends'));
@@ -878,7 +878,7 @@ class ModelTaskTest extends TestCase {
 		}
 
 		$this->Task->connection = 'test';
-		$this->Task->path = str_replace('/', DS, '/my/path/');
+		$this->Task->path = $this->_normalizePath('/my/path/');
 		$this->Task->args = ['all'];
 		$this->Task->skipTables = ['bake_tags'];
 
@@ -887,32 +887,32 @@ class ModelTaskTest extends TestCase {
 		$this->Task->Test->expects($this->exactly(7))
 			->method('bake');
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeArticle.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeArticle.php');
 		$this->Task->expects($this->at(1))
 			->method('createFile')
 			->with($filename);
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeArticlesBakeTag.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeArticlesBakeTag.php');
 		$this->Task->expects($this->at(3))
 			->method('createFile')
 			->with($filename);
 
-		$filename = str_replace('/', DS, '/my/path/Entity/BakeComment.php');
+		$filename = $this->_normalizePath('/my/path/Entity/BakeComment.php');
 		$this->Task->expects($this->at(5))
 			->method('createFile')
 			->with($filename);
 
-		$filename = str_replace('/', DS, '/my/path/Entity/CategoryThread.php');
+		$filename = $this->_normalizePath('/my/path/Entity/CategoryThread.php');
 		$this->Task->expects($this->at(7))
 			->method('createFile')
 			->with($filename);
 
-		$filename = str_replace('/', DS, '/my/path/Entity/CounterCacheUser.php');
+		$filename = $this->_normalizePath('/my/path/Entity/CounterCacheUser.php');
 		$this->Task->expects($this->at(9))
 			->method('createFile')
 			->with($filename);
 
-		$filename = str_replace('/', DS, '/my/path/Entity/NumberTree.php');
+		$filename = $this->_normalizePath('/my/path/Entity/NumberTree.php');
 		$this->Task->expects($this->at(11))
 			->method('createFile')
 			->with($filename);

+ 6 - 6
tests/TestCase/Console/ShellDispatcherTest.php

@@ -135,8 +135,8 @@ class ShellDispatcherTest extends TestCase {
 		$expected = array(
 			'app' => 'new',
 			'webroot' => 'webroot',
-			'working' => str_replace('/', DS, '/var/www/htdocs/new'),
-			'root' => str_replace('/', DS, '/var/www/htdocs')
+			'working' => $this->_normalizePath('/var/www/htdocs/new'),
+			'root' => $this->_normalizePath('/var/www/htdocs')
 		);
 		$Dispatcher->parseParams($params);
 		$this->assertEquals($expected, $Dispatcher->params);
@@ -265,8 +265,8 @@ class ShellDispatcherTest extends TestCase {
 		$expected = array(
 			'app' => 'app',
 			'webroot' => 'webroot',
-			'working' => str_replace('/', DS, '/cake/1.2.x.x/app'),
-			'root' => str_replace('/', DS, '/cake/1.2.x.x'),
+			'working' => $this->_normalizePath('/cake/1.2.x.x/app'),
+			'root' => $this->_normalizePath('/cake/1.2.x.x'),
 		);
 		$Dispatcher->params = $Dispatcher->args = array();
 		$Dispatcher->parseParams($params);
@@ -361,8 +361,8 @@ class ShellDispatcherTest extends TestCase {
 		$expected = array(
 			'app' => 'old',
 			'webroot' => 'webroot',
-			'working' => str_replace('/', DS, '/var/www/htdocs/old'),
-			'root' => str_replace('/', DS, '/var/www/htdocs')
+			'working' => $this->_normalizePath('/var/www/htdocs/old'),
+			'root' => $this->_normalizePath('/var/www/htdocs')
 		);
 		$Dispatcher->parseParams($params);
 		$this->assertEquals($expected, $Dispatcher->params);