Fix most coding standards issues in TestSuite/

This commit is contained in:
mark_story 2012-03-04 21:51:44 -05:00
parent 9a6ad7e1e2
commit c2f42343a3
19 changed files with 104 additions and 75 deletions

View file

@ -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
}

View file

@ -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';
}

View file

@ -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();
}
}

View file

@ -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;
}
}

View file

@ -28,6 +28,7 @@ App::uses('CakeTestSuiteCommand', 'TestSuite');
* @package Cake.TestSuite
*/
class CakeTestSuiteDispatcher {
/**
* 'Request' parameters
*
@ -255,4 +256,5 @@ class CakeTestSuiteDispatcher {
exit();
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -197,4 +197,5 @@ HTML;
public function coverageFooter() {
return "</pre></div></div>";
}
}

View file

@ -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];

View file

@ -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;
}
}

View file

@ -21,7 +21,9 @@ App::uses('Model', 'Model');
* @package Cake.TestSuite.Fixture
*/
class CakeTestModel extends Model {
public $useDbConfig = 'test';
public $cacheSources = false;
/**

View file

@ -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);
}

View file

@ -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 .= "<li><a href='" . $this->baseUrl() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n";
$buffer .= "<li><a href='" . $this->baseUrl() . "?case=" . urlencode($testCase) . $urlExtra . "'>" . $title . "</a></li>\n";
}
$buffer .= "</ul>\n";
echo $buffer;
@ -123,7 +123,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
*/
public function paintFooter($result) {
ob_end_flush();
$colour = ($result->failureCount() + $result->errorCount() > 0 ? "red" : "green");
$colour = ($result->failureCount() + $result->errorCount() > 0 ? "red" : "green");
echo "</ul>\n";
echo "<div style=\"";
echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;";
@ -185,7 +185,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
}
if (!empty($this->params['case'])) {
$query['case'] = $this->params['case'];
}
}
$show = $this->_queryString($show);
$query = $this->_queryString($query);
@ -345,6 +345,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
if (!$this->_headerSent) {
echo $this->paintHeader();
}
echo '<h2>' . __d('cake_dev', 'Running %s', $suite->getName()) . '</h2>';
echo '<h2>' . __d('cake_dev', 'Running %s', $suite->getName()) . '</h2>';
}
}

View file

@ -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";

View file

@ -25,9 +25,7 @@
<li><a href='<?php echo $cases;?>'>Tests</a></li>
</ul>
</li>
<?php
if (!empty($plugins)):
?>
<?php if (!empty($plugins)): ?>
<li style="padding-top: 10px">
<span style="font-size: 18px">Plugins</span>
<?php foreach ($plugins as $plugin): ?>

View file

@ -23,4 +23,5 @@
<h3><?php echo $exception->getMessage(); ?></h3>
<pre><?php echo $exception->getTraceAsString(); ?></pre>
</div>
<?php include dirname(__FILE__) . DS . 'footer.php'; ?>
<?php
include dirname(__FILE__) . DS . 'footer.php';

View file

@ -34,4 +34,5 @@
<p>For full instructions on how to <a href="http://www.phpunit.de/manual/current/en/installation.html">install PHPUnit, see the PHPUnit installation guide</a>.</p>
<p><a href="http://github.com/sebastianbergmann/phpunit" target="_blank">Download PHPUnit</a></p>
</div>
<?php include dirname(__FILE__) . DS . 'footer.php'; ?>
<?php
include dirname(__FILE__) . DS . 'footer.php';

View file

@ -23,4 +23,6 @@
<p>You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation.</p>
<p><a href="http://www.xdebug.org/docs/install" target="_blank">Learn How To Install Xdebug</a></p>
</div>
<?php include dirname(__FILE__) . DS . 'footer.php'; ?>
<?php
include dirname(__FILE__) . DS . 'footer.php';

View file

@ -30,4 +30,5 @@
<?php echo __d('cake_dev', 'If you want to customize this error message, create %s.', APP_DIR . DS . 'View' . DS . 'Errors' . DS . basename(__FILE__)); ?>
</p>
<?php echo $this->element('exception_stack_trace'); ?>
<?php
echo $this->element('exception_stack_trace');