mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 00:48:25 +00:00
Removing duplicate class definition that could cause test suite inconsistencies.
Adding skip for when AppController is defined. Changing how mock models are constructed to better use Model::__construct parameters.
This commit is contained in:
parent
9dcea304c1
commit
862a2bc25e
2 changed files with 11 additions and 12 deletions
|
@ -20,7 +20,9 @@
|
||||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||||
*/
|
*/
|
||||||
App::import('Controller', 'Controller', false);
|
App::import('Controller', 'Controller', false);
|
||||||
|
App::import('Core', array('AppModel', 'Model'));
|
||||||
require_once TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_html_reporter.php';
|
require_once TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'lib' . DS . 'reporter' . DS . 'cake_html_reporter.php';
|
||||||
|
require_once dirname(__FILE__) . DS . 'model' . DS . 'models.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AppController class
|
* AppController class
|
||||||
|
@ -81,13 +83,6 @@ if (!class_exists('PostsController')) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Post model
|
|
||||||
*/
|
|
||||||
if (!class_exists('Post')) {
|
|
||||||
class Post extends CakeTestModel {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ControllerTestCaseTest
|
* ControllerTestCaseTest
|
||||||
|
@ -103,7 +98,7 @@ class ControllerTestCaseTest extends CakeTestCase {
|
||||||
* @var array
|
* @var array
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
public $fixtures = array('core.post');
|
public $fixtures = array('core.post', 'core.author');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reset environment.
|
* reset environment.
|
||||||
|
@ -136,6 +131,9 @@ class ControllerTestCaseTest extends CakeTestCase {
|
||||||
* Test that ControllerTestCase::generate() creates mock objects correctly
|
* Test that ControllerTestCase::generate() creates mock objects correctly
|
||||||
*/
|
*/
|
||||||
function testGenerate() {
|
function testGenerate() {
|
||||||
|
if (defined('APP_CONTROLLER_EXISTS')) {
|
||||||
|
$this->markTestSkipped('AppController exists, cannot run.');
|
||||||
|
}
|
||||||
$Posts = $this->Case->generate('Posts');
|
$Posts = $this->Case->generate('Posts');
|
||||||
$this->assertEquals($Posts->name, 'Posts');
|
$this->assertEquals($Posts->name, 'Posts');
|
||||||
$this->assertEquals($Posts->modelClass, 'Post');
|
$this->assertEquals($Posts->modelClass, 'Post');
|
||||||
|
@ -153,6 +151,7 @@ class ControllerTestCaseTest extends CakeTestCase {
|
||||||
'components' => array('RequestHandler')
|
'components' => array('RequestHandler')
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Post', $Posts->Post);
|
||||||
$this->assertNull($Posts->Post->save(array()));
|
$this->assertNull($Posts->Post->save(array()));
|
||||||
$this->assertNull($Posts->Post->find('all'));
|
$this->assertNull($Posts->Post->find('all'));
|
||||||
$this->assertEquals($Posts->Post->useTable, 'posts');
|
$this->assertEquals($Posts->Post->useTable, 'posts');
|
||||||
|
|
|
@ -242,6 +242,7 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
* interfere with testing.
|
* interfere with testing.
|
||||||
*
|
*
|
||||||
* ### Mocks:
|
* ### Mocks:
|
||||||
|
*
|
||||||
* - `methods` Methods to mock on the controller. `_stop()` is mocked by default
|
* - `methods` Methods to mock on the controller. `_stop()` is mocked by default
|
||||||
* - `models` Models to mock. Models are added to the ClassRegistry so they any
|
* - `models` Models to mock. Models are added to the ClassRegistry so they any
|
||||||
* time they are instatiated the mock will be created. Pass as key value pairs
|
* time they are instatiated the mock will be created. Pass as key value pairs
|
||||||
|
@ -270,6 +271,7 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
$_controller->name = $controller;
|
$_controller->name = $controller;
|
||||||
$_controller->__construct();
|
$_controller->__construct();
|
||||||
|
|
||||||
|
$config = ClassRegistry::config('Model');
|
||||||
foreach ($mocks['models'] as $model => $methods) {
|
foreach ($mocks['models'] as $model => $methods) {
|
||||||
if (is_string($methods)) {
|
if (is_string($methods)) {
|
||||||
$model = $methods;
|
$model = $methods;
|
||||||
|
@ -278,10 +280,8 @@ class ControllerTestCase extends CakeTestCase {
|
||||||
if ($methods === true) {
|
if ($methods === true) {
|
||||||
$methods = array();
|
$methods = array();
|
||||||
}
|
}
|
||||||
ClassRegistry::init($model);
|
$config = array_merge((array)$config, array('name' => $model));
|
||||||
$_model = $this->getMock($model, $methods, array(), '', false);
|
$_model = $this->getMock($model, $methods, array($config));
|
||||||
$_model->name = $model;
|
|
||||||
$_model->__construct();
|
|
||||||
ClassRegistry::removeObject($model);
|
ClassRegistry::removeObject($model);
|
||||||
ClassRegistry::addObject($model, $_model);
|
ClassRegistry::addObject($model, $_model);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue