Skip to content
Permalink
Browse files

Fix failing tests that were relying of 2.x implementation details.

* Rename classes.
* Add missing use statements.
* Change config management.
  • Loading branch information...
markstory committed Aug 13, 2013
1 parent cf182af commit 5927cd357ba69ea96d1ce091cfb40997258d92ca
@@ -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)) {
@@ -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;
@@ -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;
}
/**
@@ -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;
}
}
@@ -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'
));
@@ -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');
}
}
@@ -19,6 +19,7 @@
*/
namespace Cake\Test\TestCase\I18n;
use Cake\Core\Configure;
use Cake\I18n\L10n;
use Cake\TestSuite\TestCase;
@@ -372,7 +372,7 @@ public function testCompress() {
/**
* Tests the httpCodes method
*
* @expectedException CakeException
* @expectedException Cake\Error\Exception
*/
public function testHttpCodes() {
$response = new Response();
@@ -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')
);
}
@@ -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';
@@ -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();
@@ -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')
@@ -425,7 +425,7 @@ public function testGetMockForModelModel() {
/**
* testGetMockForModelDoesNotExist
*
* @expectedException MissingModelException
* @expectedException Cake\Error\MissingModelException
* @expectedExceptionMessage Model IDoNotExist could not be found
* @return void
*/
@@ -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'));
@@ -282,7 +282,6 @@ public function insert(Connection $db) {
foreach ($values as $row) {
$query->values($row);
}
return $query->execute();
}
return true;
@@ -21,6 +21,7 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Error;
use Cake\Routing\Router;
use Cake\Utility\ClassRegistry;
@@ -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;
@@ -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);

0 comments on commit 5927cd3

Please sign in to comment.
You can’t perform that action at this time.