Skip to content

Commit

Permalink
Fix failing tests that were relying of 2.x implementation details.
Browse files Browse the repository at this point in the history
* Rename classes.
* Add missing use statements.
* Change config management.
  • Loading branch information
markstory committed Aug 13, 2013
1 parent cf182af commit 5927cd3
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 50 deletions.
4 changes: 2 additions & 2 deletions lib/Cake/Network/Response.php
Expand Up @@ -658,7 +658,7 @@ public function statusCode($code = null) {
*
* @return mixed associative array of the HTTP codes as keys, and the message
* strings as values, or null of the given $code does not exist.
* @throws CakeException If an attempt is made to add an invalid status code
* @throws Cake\Error\Exception If an attempt is made to add an invalid status code
*/
public function httpCodes($code = null) {
if (empty($code)) {
Expand All @@ -668,7 +668,7 @@ public function httpCodes($code = null) {
$codes = array_keys($code);
$min = min($codes);
if (!is_int($min) || $min < 100 || max($codes) > 999) {
throw new CakeException(__d('cake_dev', 'Invalid status code'));
throw new Error\Exception(__d('cake_dev', 'Invalid status code'));
}
$this->_statusCodes = $code + $this->_statusCodes;
return true;
Expand Down
16 changes: 9 additions & 7 deletions lib/Cake/Routing/RouteCollection.php
Expand Up @@ -100,14 +100,13 @@ public function match($url) {
* @return mixed Either false on failure, or a string on success.
*/
protected function _matchRoutes($routes, $url) {
$output = false;
for ($i = 0, $len = count($routes); $i < $len; $i++) {
if ($match = $routes[$i]->match($url, $this->_requestContext)) {
$output = trim($match, '/');
break;
$match = $routes[$i]->match($url, $this->_requestContext);
if ($match) {
return strlen($match) > 1 ? trim($match, '/') : $match;
}
}
return $output;
return false;
}

/**
Expand Down Expand Up @@ -159,16 +158,19 @@ protected function _getNames($url) {
* @return array An array of request parameters parsed from the url.
*/
public function parse($url) {
$queryParameters = [];
$queryParameters = null;
if (strpos($url, '?') !== false) {
list($url, $queryParameters) = explode('?', $url, 2);
parse_str($queryParameters, $queryParameters);
}
$out = array();
for ($i = 0, $len = count($this); $i < $len; $i++) {
$r = $this->_routes[$i]->parse($url);
if ($r !== false && $queryParameters) {
$r['?'] = $queryParameters;
return $r;
}
if ($r !== false) {
$r['?'] = isset($r['?']) ? $r['?'] : $queryParameters;
return $r;
}
}
Expand Down
22 changes: 1 addition & 21 deletions lib/Cake/Test/TestCase/Cache/Engine/FileEngineTest.php
Expand Up @@ -371,7 +371,7 @@ public function testWriteQuotedString() {
public function testPathDoesNotExist() {
$this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.');

Cache::config('autocreate', array(
Configure::write('Cache.autocreate', array(
'engine' => 'File',
'path' => TMP . 'tests' . DS . 'autocreate'
));
Expand Down Expand Up @@ -527,24 +527,4 @@ public function testGroupClear() {
$this->assertEquals('value 3', Cache::read('test_groups6', 'file_groups3'));
}

/**
* testInvalidConfig method
*
* Test that the cache class doesn't cause fatal errors with a partial path
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testInvalidConfig() {
Configure::write('Cache.invalid', [
'engine' => 'File',
'duration' => '+1 year',
'prefix' => 'testing_invalid_',
'path' => 'data/',
'serialize' => true,
'random' => 'wii'
]);
Cache::read('Test', 'invalid');
}

}
1 change: 1 addition & 0 deletions lib/Cake/Test/TestCase/I18n/L10nTest.php
Expand Up @@ -19,6 +19,7 @@
*/
namespace Cake\Test\TestCase\I18n;

use Cake\Core\Configure;
use Cake\I18n\L10n;
use Cake\TestSuite\TestCase;

Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/TestCase/Network/ResponseTest.php
Expand Up @@ -372,7 +372,7 @@ public function testCompress() {
/**
* Tests the httpCodes method
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
*/
public function testHttpCodes() {
$response = new Response();
Expand Down
11 changes: 2 additions & 9 deletions lib/Cake/Test/TestCase/Routing/RouterTest.php
Expand Up @@ -1376,8 +1376,6 @@ public function parseReverseSymmetryData() {
array('/controller/action/param'),
array('/controller/action?param1=value1&param2=value2'),
array('/controller/action/param?param1=value1'),
array('/controller/action/named1:nv1'),
array('/controller/action/named1:nv1?param1=value1')
);
}

Expand Down Expand Up @@ -1557,11 +1555,6 @@ public function testExtensionParsing() {
$expected['?'] = array('query' => 'test');
$this->assertEquals($expected, $result);

$result = Router::parse('/posts/view/1.atom');
unset($expected['?']);
$expected['ext'] = 'atom';
$this->assertEquals($expected, $result);

Router::reload();
Router::parseExtensions('rss', 'xml');
require CAKE . 'Config/routes.php';
Expand All @@ -1587,9 +1580,9 @@ public function testExtensionParsing() {
$this->assertEquals($expected, $result);

Router::reload();
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', 'ext' => 'rss'));
Router::connect('/controller/action', array('controller' => 'controller', 'action' => 'action', '_ext' => 'rss'));
$result = Router::parse('/controller/action');
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'ext' => 'rss', 'named' => array(), 'pass' => array());
$expected = array('controller' => 'controller', 'action' => 'action', 'plugin' => null, '_ext' => 'rss', 'pass' => array());
$this->assertEquals($expected, $result);

Router::reload();
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/TestCase/TestSuite/TestCaseTest.php
Expand Up @@ -409,7 +409,7 @@ public function testGetMockForModelModel() {
$Mock = $this->getMockForModel('Model', array('save'), array('name' => 'Comment'));

$result = ClassRegistry::init('Comment');
$this->assertInstanceOf('Model', $result);
$this->assertInstanceOf('Cake\Model\Model', $result);

$Mock->expects($this->at(0))
->method('save')
Expand All @@ -425,7 +425,7 @@ public function testGetMockForModelModel() {
/**
* testGetMockForModelDoesNotExist
*
* @expectedException MissingModelException
* @expectedException Cake\Error\MissingModelException
* @expectedExceptionMessage Model IDoNotExist could not be found
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/TestCase/View/Helper/TimeHelperTest.php
Expand Up @@ -105,8 +105,8 @@ public function testTimeHelperProxyMethodCalls() {
$Time->{$method}('who', 'what', 'when', 'where', 'how');
}

$CakeTime = $this->getMock('CakeTimeMock', array('timeAgoInWords'));
$Time = new TimeHelperTestObject($this->View, array('engine' => 'CakeTimeMock'));
$CakeTime = $this->getMock(__NAMESPACE__ . '\TimeMock', array('timeAgoInWords'));
$Time = new TimeHelperTestObject($this->View, array('engine' => __NAMESPACE__ . '\TimeMock'));
$Time->attach($CakeTime);
$CakeTime->expects($this->at(0))->method('timeAgoInWords');
$Time->timeAgoInWords('who', array('what'), array('when'), array('where'), array('how'));
Expand Down
1 change: 0 additions & 1 deletion lib/Cake/TestSuite/Fixture/TestFixture.php
Expand Up @@ -282,7 +282,6 @@ public function insert(Connection $db) {
foreach ($values as $row) {
$query->values($row);
}

return $query->execute();
}
return true;
Expand Down
7 changes: 4 additions & 3 deletions lib/Cake/TestSuite/TestCase.php
Expand Up @@ -21,6 +21,7 @@

use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Routing\Router;
use Cake\Utility\ClassRegistry;

Expand Down Expand Up @@ -702,11 +703,11 @@ public function getMockForModel($model, $methods = array(), $config = array()) {
$modelClass = App::className($model, 'Model');
list(, $name) = namespaceSplit($modelClass);
$config = array_merge((array)$config, array('name' => $name));
if (!class_exists($name)) {
throw new MissingModelException(array($model));
if (!$modelClass) {
throw new Error\MissingModelException(array($model));
}

$mock = $this->getMock($name, $methods, array($config));
$mock = $this->getMock($modelClass, $methods, array($config));
ClassRegistry::removeObject($name);
ClassRegistry::addObject($name, $mock);
return $mock;
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Utility/Debugger.php
Expand Up @@ -595,8 +595,8 @@ protected static function _object($var, $depth, $indent) {
$ref = new \ReflectionObject($var);

$filters = array(
ReflectionProperty::IS_PROTECTED => 'protected',
ReflectionProperty::IS_PRIVATE => 'private',
\ReflectionProperty::IS_PROTECTED => 'protected',
\ReflectionProperty::IS_PRIVATE => 'private',
);
foreach ($filters as $filter => $visibility) {
$reflectionProperties = $ref->getProperties($filter);
Expand Down

0 comments on commit 5927cd3

Please sign in to comment.