From c2f42343a355f7935d8f2ca34e86d4bc7018d3d6 Mon Sep 17 00:00:00 2001
From: mark_story
Date: Sun, 4 Mar 2012 21:51:44 -0500
Subject: [PATCH] Fix most coding standards issues in TestSuite/
---
lib/Cake/TestSuite/CakeTestCase.php | 44 +++++++++------
lib/Cake/TestSuite/CakeTestLoader.php | 3 +-
lib/Cake/TestSuite/CakeTestRunner.php | 5 ++
lib/Cake/TestSuite/CakeTestSuiteCommand.php | 6 +-
.../TestSuite/CakeTestSuiteDispatcher.php | 2 +
lib/Cake/TestSuite/ControllerTestCase.php | 9 ++-
.../TestSuite/Coverage/BaseCoverageReport.php | 4 +-
.../TestSuite/Coverage/HtmlCoverageReport.php | 1 +
.../TestSuite/Fixture/CakeFixtureManager.php | 4 +-
.../TestSuite/Fixture/CakeTestFixture.php | 11 +++-
lib/Cake/TestSuite/Fixture/CakeTestModel.php | 2 +
.../TestSuite/Reporter/CakeBaseReporter.php | 56 ++++++++-----------
.../TestSuite/Reporter/CakeHtmlReporter.php | 9 +--
.../TestSuite/Reporter/CakeTextReporter.php | 6 +-
lib/Cake/TestSuite/templates/menu.php | 4 +-
.../templates/missing_connection.php | 3 +-
lib/Cake/TestSuite/templates/phpunit.php | 3 +-
lib/Cake/TestSuite/templates/xdebug.php | 4 +-
lib/Cake/View/Errors/missing_connection.ctp | 3 +-
19 files changed, 104 insertions(+), 75 deletions(-)
diff --git a/lib/Cake/TestSuite/CakeTestCase.php b/lib/Cake/TestSuite/CakeTestCase.php
index f1f21eb6c..9619a6c95 100644
--- a/lib/Cake/TestSuite/CakeTestCase.php
+++ b/lib/Cake/TestSuite/CakeTestCase.php
@@ -63,15 +63,15 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
protected $_pathRestore = array();
/**
-* Runs the test case and collects the results in a TestResult object.
-* If no TestResult object is passed a new one will be created.
-* This method is run for each test method in this class
-*
-* @param PHPUnit_Framework_TestResult $result
-* @return PHPUnit_Framework_TestResult
-* @throws InvalidArgumentException
-*/
- public function run(PHPUnit_Framework_TestResult $result = NULL) {
+ * Runs the test case and collects the results in a TestResult object.
+ * If no TestResult object is passed a new one will be created.
+ * This method is run for each test method in this class
+ *
+ * @param PHPUnit_Framework_TestResult $result
+ * @return PHPUnit_Framework_TestResult
+ * @throws InvalidArgumentException
+ */
+ public function run(PHPUnit_Framework_TestResult $result = null) {
if (!empty($this->fixtureManager)) {
$this->fixtureManager->load($this);
}
@@ -152,6 +152,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
}
}
+// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
+
/**
* Announces the start of a test.
*
@@ -174,6 +176,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$this->endTest($this->getName());
}
+// @codingStandardsIgnoreEnd
+
/**
* Chooses which fixtures to load for a given test
*
@@ -181,6 +185,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* fixture, i.e. 'Post', 'Author', etc.
* @return void
* @see CakeTestCase::$autoFixtures
+ * @throws Exception when no fixture manager is available.
*/
public function loadFixtures() {
if (empty($this->fixtureManager)) {
@@ -230,7 +235,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @param string $string
* @param string $message
* @return boolean
- */
+ */
public function assertTextStartsWith($prefix, $string, $message = '') {
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
@@ -245,7 +250,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @param string $string
* @param string $message
* @return boolean
- */
+ */
public function assertTextStartsNotWith($prefix, $string, $message = '') {
$prefix = str_replace(array("\r\n", "\r"), "\n", $prefix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
@@ -260,7 +265,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @param string $string
* @param string $message
* @return boolean
- */
+ */
public function assertTextEndsWith($suffix, $string, $message = '') {
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
@@ -280,7 +285,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$suffix = str_replace(array("\r\n", "\r"), "\n", $suffix);
$string = str_replace(array("\r\n", "\r"), "\n", $string);
return $this->assertStringEndsNotWith($suffix, $string, $message);
- }
+ }
/**
* Assert that a string contains another string, ignoring differences in newlines.
@@ -350,7 +355,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
public function assertTags($string, $expected, $fullDebug = false) {
$regex = array();
$normalized = array();
- foreach ((array) $expected as $key => $val) {
+ foreach ((array)$expected as $key => $val) {
if (!is_numeric($key)) {
$normalized[] = array($key => $val);
} else {
@@ -431,7 +436,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$i++;
}
if ($attrs) {
- $permutations = $this->_array_permute($attrs);
+ $permutations = $this->_arrayPermute($attrs);
$permutationTokens = array();
foreach ($permutations as $permutation) {
@@ -480,7 +485,7 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* @param array $items An array of items
* @return array
*/
- protected function _array_permute($items, $perms = array()) {
+ protected function _arrayPermute($items, $perms = array()) {
static $permuted;
if (empty($perms)) {
$permuted = array();
@@ -495,15 +500,18 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
$newPerms = $perms;
list($tmp) = array_splice($newItems, $i, 1);
array_unshift($newPerms, $tmp);
- $this->_array_permute($newItems, $newPerms);
+ $this->_arrayPermute($newItems, $newPerms);
}
return $permuted;
}
}
+// @codingStandardsIgnoreStart
+
/**
* Compatibility wrapper function for assertEquals
*
+ *
* @param mixed $result
* @param mixed $expected
* @param string $message the text to display if the assertion is not correct
@@ -653,4 +661,6 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
}
return $condition;
}
+ // @codingStandardsIgnoreStop
+
}
diff --git a/lib/Cake/TestSuite/CakeTestLoader.php b/lib/Cake/TestSuite/CakeTestLoader.php
index bca88d4ca..cfb8fc968 100644
--- a/lib/Cake/TestSuite/CakeTestLoader.php
+++ b/lib/Cake/TestSuite/CakeTestLoader.php
@@ -66,7 +66,8 @@ class CakeTestLoader extends PHPUnit_Runner_StandardTestSuiteLoader {
try {
CakePlugin::load($params['plugin']);
$result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
- } catch (MissingPluginException $e) {}
+ } catch (MissingPluginException $e) {
+ }
} else {
$result = CakePlugin::path($params['plugin']) . 'Test' . DS . 'Case';
}
diff --git a/lib/Cake/TestSuite/CakeTestRunner.php b/lib/Cake/TestSuite/CakeTestRunner.php
index f4eb51495..a15beeb5b 100644
--- a/lib/Cake/TestSuite/CakeTestRunner.php
+++ b/lib/Cake/TestSuite/CakeTestRunner.php
@@ -23,6 +23,7 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
* @package Cake.TestSuite
*/
class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
+
/**
* Lets us pass in some options needed for cake's webrunner.
*
@@ -58,6 +59,7 @@ class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
return $return;
}
+// @codingStandardsIgnoreStart PHPUnit overrides don't match CakePHP
/**
* Create the test result and splice on our code coverage reports.
*
@@ -75,11 +77,13 @@ class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
}
return $result;
}
+// @codingStandardsIgnoreEnd
/**
* Get the fixture manager class specified or use the default one.
*
* @return instance of a fixture manager.
+ * @throws RuntimeException When fixture manager class cannot be loaded.
*/
protected function _getFixtureManager($arguments) {
if (isset($arguments['fixtureManager'])) {
@@ -95,4 +99,5 @@ class CakeTestRunner extends PHPUnit_TextUI_TestRunner {
}
return new CakeFixtureManager();
}
+
}
diff --git a/lib/Cake/TestSuite/CakeTestSuiteCommand.php b/lib/Cake/TestSuite/CakeTestSuiteCommand.php
index 29953b5d2..1a8c07065 100644
--- a/lib/Cake/TestSuite/CakeTestSuiteCommand.php
+++ b/lib/Cake/TestSuite/CakeTestSuiteCommand.php
@@ -37,6 +37,7 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
* Construct method
*
* @param array $params list of options to be used for this run
+ * @throws MissingTestLoaderException When a loader class could not be found.
*/
public function __construct($loader, $params = array()) {
if ($loader && !class_exists($loader)) {
@@ -117,9 +118,7 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
} elseif (!isset($result) || $result->errorCount() > 0) {
exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
- }
-
- else {
+ } else {
exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
}
}
@@ -168,4 +167,5 @@ class CakeTestSuiteCommand extends PHPUnit_TextUI_Command {
}
return $this->arguments['printer'] = $object;
}
+
}
diff --git a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
index 8ca8adbd7..5f83cd2e3 100644
--- a/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
+++ b/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php
@@ -28,6 +28,7 @@ App::uses('CakeTestSuiteCommand', 'TestSuite');
* @package Cake.TestSuite
*/
class CakeTestSuiteDispatcher {
+
/**
* 'Request' parameters
*
@@ -255,4 +256,5 @@ class CakeTestSuiteDispatcher {
exit();
}
}
+
}
diff --git a/lib/Cake/TestSuite/ControllerTestCase.php b/lib/Cake/TestSuite/ControllerTestCase.php
index 9d5c5a23a..a3b19f438 100644
--- a/lib/Cake/TestSuite/ControllerTestCase.php
+++ b/lib/Cake/TestSuite/ControllerTestCase.php
@@ -80,6 +80,7 @@ class ControllerTestDispatcher extends Dispatcher {
Router::reload();
}
}
+
}
/**
@@ -98,6 +99,7 @@ class InterceptContentHelper extends Helper {
$this->_View->assign('__view_no_layout__', $this->_View->fetch('content'));
$this->_View->Helpers->unload('InterceptContent');
}
+
}
/**
@@ -291,6 +293,8 @@ abstract class ControllerTestCase extends CakeTestCase {
* @param string $controller Controller name
* @param array $mocks List of classes and methods to mock
* @return Controller Mocked controller
+ * @throws MissingControllerException When controllers could not be created.
+ * @throws MissingComponentException When components could not be created.
*/
public function generate($controller, $mocks = array()) {
list($plugin, $controller) = pluginSplit($controller);
@@ -299,7 +303,7 @@ abstract class ControllerTestCase extends CakeTestCase {
$plugin .= '.';
}
App::uses($controller . 'Controller', $plugin . 'Controller');
- if (!class_exists($controller.'Controller')) {
+ if (!class_exists($controller . 'Controller')) {
throw new MissingControllerException(array(
'class' => $controller . 'Controller',
'plugin' => substr($plugin, 0, -1)
@@ -314,7 +318,7 @@ abstract class ControllerTestCase extends CakeTestCase {
), (array)$mocks);
list($plugin, $name) = pluginSplit($controller);
- $_controller = $this->getMock($name.'Controller', $mocks['methods'], array(), '', false);
+ $_controller = $this->getMock($name . 'Controller', $mocks['methods'], array(), '', false);
$_controller->name = $name;
$request = $this->getMock('CakeRequest');
$response = $this->getMock('CakeResponse', array('_sendHeader'));
@@ -363,4 +367,5 @@ abstract class ControllerTestCase extends CakeTestCase {
$this->controller = $_controller;
return $this->controller;
}
+
}
diff --git a/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php b/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php
index a8e244a6b..c732f93ea 100644
--- a/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php
+++ b/lib/Cake/TestSuite/Coverage/BaseCoverageReport.php
@@ -64,7 +64,7 @@ abstract class BaseCoverageReport {
*/
public function __construct($coverage, CakeBaseReporter $reporter) {
$this->_rawCoverage = $coverage;
- $this->setParams($reporter);
+ $this->_setParams($reporter);
}
/**
@@ -73,7 +73,7 @@ abstract class BaseCoverageReport {
* @param CakeBaseReporter $reporter Reporter to suck params out of.
* @return void
*/
- protected function setParams(CakeBaseReporter $reporter) {
+ protected function _setParams(CakeBaseReporter $reporter) {
if ($reporter->params['app']) {
$this->appTest = true;
}
diff --git a/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php b/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php
index d38cbc516..9bb1da242 100644
--- a/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php
+++ b/lib/Cake/TestSuite/Coverage/HtmlCoverageReport.php
@@ -197,4 +197,5 @@ HTML;
public function coverageFooter() {
return "";
}
+
}
diff --git a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
index b49afd34a..84f814c46 100644
--- a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
+++ b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php
@@ -127,7 +127,7 @@ class CakeFixtureManager {
} else {
$fixturePaths = array(
TESTS . 'Fixture',
- CAKE . 'Test' . DS . 'Fixture'
+ CAKE . 'Test' . DS . 'Fixture'
);
}
@@ -135,7 +135,7 @@ class CakeFixtureManager {
$className = Inflector::camelize($fixture);
if (is_readable($path . DS . $className . 'Fixture.php')) {
$fixtureFile = $path . DS . $className . 'Fixture.php';
- require_once($fixtureFile);
+ require_once $fixtureFile;
$fixtureClass = $className . 'Fixture';
$this->_loaded[$fixtureIndex] = new $fixtureClass();
$this->_fixtureMap[$fixtureClass] = $this->_loaded[$fixtureIndex];
diff --git a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php
index e498577a8..06813ac3d 100644
--- a/lib/Cake/TestSuite/Fixture/CakeTestFixture.php
+++ b/lib/Cake/TestSuite/Fixture/CakeTestFixture.php
@@ -33,30 +33,35 @@ class CakeTestFixture {
/**
* Cake's DBO driver (e.g: DboMysql).
*
+ * @var object
*/
public $db = null;
/**
* Fixture Datasource
*
+ * @var string
*/
public $useDbConfig = 'test';
/**
* Full Table Name
*
+ * @var string
*/
public $table = null;
/**
* List of datasources where this fixture has been created
*
+ * @var array
*/
public $created = array();
/**
* Instantiate the fixture.
*
+ * @throws CakeException on invalid datasource usage.
*/
public function __construct() {
if ($this->name === null) {
@@ -80,6 +85,8 @@ class CakeTestFixture {
/**
* Initialize the fixture.
*
+ * @return void
+ * @throws MissingModelException Whe importing from a model that does not exist.
*/
public function init() {
if (isset($this->import) && (is_string($this->import) || is_array($this->import))) {
@@ -206,7 +213,7 @@ class CakeTestFixture {
try {
$db->execute($db->dropSchema($this->Schema), array('log' => false));
- $this->created = array_diff($this->created, array($db->configKeyName));;
+ $this->created = array_diff($this->created, array($db->configKeyName));
} catch (Exception $e) {
return false;
}
@@ -240,7 +247,6 @@ class CakeTestFixture {
}
}
-
/**
* Truncates the current fixture. Can be overwritten by classes extending CakeFixture to trigger other events before / after
* truncate.
@@ -255,4 +261,5 @@ class CakeTestFixture {
$db->fullDebug = $fullDebug;
return $return;
}
+
}
diff --git a/lib/Cake/TestSuite/Fixture/CakeTestModel.php b/lib/Cake/TestSuite/Fixture/CakeTestModel.php
index bed356253..74222cc35 100644
--- a/lib/Cake/TestSuite/Fixture/CakeTestModel.php
+++ b/lib/Cake/TestSuite/Fixture/CakeTestModel.php
@@ -21,7 +21,9 @@ App::uses('Model', 'Model');
* @package Cake.TestSuite.Fixture
*/
class CakeTestModel extends Model {
+
public $useDbConfig = 'test';
+
public $cacheSources = false;
/**
diff --git a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php b/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php
index 9be119dda..ed31b66e4 100644
--- a/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php
+++ b/lib/Cake/TestSuite/Reporter/CakeBaseReporter.php
@@ -40,11 +40,6 @@ class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
*/
protected $_characterSet;
-/**
-* The number of assertions done for a test suite
-*/
- protected $numAssertions = 0;
-
/**
* Does nothing yet. The first output will
* be sent on the first test start.
@@ -86,7 +81,6 @@ class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
* @return void
*/
public function paintDocumentStart() {
-
}
/**
@@ -96,7 +90,6 @@ class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
* @return void
*/
public function paintDocumentEnd() {
-
}
/**
@@ -106,7 +99,6 @@ class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
* @return void
*/
public function paintTestMenu() {
-
}
/**
@@ -130,45 +122,45 @@ class CakeBaseReporter extends PHPUnit_TextUI_ResultPrinter {
}
/**
-* An error occurred.
-*
-* @param PHPUnit_Framework_Test $test
-* @param Exception $e
-* @param float $time
-*/
+ * An error occurred.
+ *
+ * @param PHPUnit_Framework_Test $test
+ * @param Exception $e
+ * @param float $time
+ */
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
$this->paintException($e, $test);
}
/**
-* A failure occurred.
-*
-* @param PHPUnit_Framework_Test $test
-* @param PHPUnit_Framework_AssertionFailedError $e
-* @param float $time
-*/
+ * A failure occurred.
+ *
+ * @param PHPUnit_Framework_Test $test
+ * @param PHPUnit_Framework_AssertionFailedError $e
+ * @param float $time
+ */
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
$this->paintFail($e, $test);
}
/**
-* Incomplete test.
-*
-* @param PHPUnit_Framework_Test $test
-* @param Exception $e
-* @param float $time
-*/
+ * Incomplete test.
+ *
+ * @param PHPUnit_Framework_Test $test
+ * @param Exception $e
+ * @param float $time
+ */
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
$this->paintSkip($e, $test);
}
/**
-* Skipped test.
-*
-* @param PHPUnit_Framework_Test $test
-* @param Exception $e
-* @param float $time
-*/
+ * Skipped test.
+ *
+ * @param PHPUnit_Framework_Test $test
+ * @param Exception $e
+ * @param float $time
+ */
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
$this->paintSkip($e, $test);
}
diff --git a/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php b/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
index 5b3b753a0..fe10e80c9 100644
--- a/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
+++ b/lib/Cake/TestSuite/Reporter/CakeHtmlReporter.php
@@ -91,7 +91,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
$title = explode(DS, str_replace('.test.php', '', $testCase));
$title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]);
$title = implode(' / ', $title);
- $buffer .= "' . __d('cake_dev', 'Running %s', $suite->getName()) . '
';
+ echo '' . __d('cake_dev', 'Running %s', $suite->getName()) . '
';
}
+
}
diff --git a/lib/Cake/TestSuite/Reporter/CakeTextReporter.php b/lib/Cake/TestSuite/Reporter/CakeTextReporter.php
index d8dbce046..3900eef5a 100644
--- a/lib/Cake/TestSuite/Reporter/CakeTextReporter.php
+++ b/lib/Cake/TestSuite/Reporter/CakeTextReporter.php
@@ -111,8 +111,8 @@ class CakeTextReporter extends CakeBaseReporter {
*/
public function paintException($exception) {
$message = 'Unexpected exception of type [' . get_class($exception) .
- '] with message ['. $exception->getMessage() .
- '] in ['. $exception->getFile() .
+ '] with message [' . $exception->getMessage() .
+ '] in [' . $exception->getFile() .
' line ' . $exception->getLine() . ']';
echo $message . "\n\n";
}
@@ -166,7 +166,7 @@ class CakeTextReporter extends CakeBaseReporter {
}
foreach ($testCases as $testCaseFile => $testCase) {
- $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n";
+ $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() . "?case=" . $testCase . "&output=text\n";
}
$buffer .= "\n";
diff --git a/lib/Cake/TestSuite/templates/menu.php b/lib/Cake/TestSuite/templates/menu.php
index 209967617..68b07cfe5 100644
--- a/lib/Cake/TestSuite/templates/menu.php
+++ b/lib/Cake/TestSuite/templates/menu.php
@@ -25,9 +25,7 @@
getMessage(); ?>
getTraceAsString(); ?>