mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merge pull request #1539 from cakephp/feature/2.4-mock-components-with-config
BugFix: 2.4 mock components with config
This commit is contained in:
commit
a09fca579a
3 changed files with 37 additions and 1 deletions
|
@ -210,6 +210,28 @@ class ControllerTestCaseTest extends CakeTestCase {
|
||||||
$this->assertEquals('written!', $Posts->Auth->Session->write('something'));
|
$this->assertEquals('written!', $Posts->Auth->Session->write('something'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testGenerateWithComponentConfig
|
||||||
|
*/
|
||||||
|
public function testGenerateWithComponentConfig() {
|
||||||
|
$Tests = $this->Case->generate('TestConfigs', array(
|
||||||
|
));
|
||||||
|
|
||||||
|
$expected = array('some' => 'config');
|
||||||
|
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
|
||||||
|
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
|
||||||
|
|
||||||
|
$Tests = $this->Case->generate('TestConfigs', array(
|
||||||
|
'components' => array(
|
||||||
|
'RequestHandler' => array('isPut')
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
$expected = array('some' => 'config');
|
||||||
|
$settings = array_intersect_key($Tests->RequestHandler->settings, array('some' => 'foo'));
|
||||||
|
$this->assertSame($expected, $settings, 'A mocked component should have the same config as an unmocked component');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests ControllerTestCase::generate() using classes from plugins
|
* Tests ControllerTestCase::generate() using classes from plugins
|
||||||
*/
|
*/
|
||||||
|
|
13
lib/Cake/Test/test_app/Controller/TestConfigsController.php
Normal file
13
lib/Cake/Test/test_app/Controller/TestConfigsController.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
App::uses('CakeErrorController', 'Controller');
|
||||||
|
|
||||||
|
class TestConfigsController extends CakeErrorController {
|
||||||
|
|
||||||
|
public $components = array(
|
||||||
|
'RequestHandler' => array(
|
||||||
|
'some' => 'config'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
|
@ -364,7 +364,8 @@ abstract class ControllerTestCase extends CakeTestCase {
|
||||||
'class' => $componentClass
|
'class' => $componentClass
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
$componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components));
|
$config = isset($controllerObj->components[$component]) ? $controllerObj->components[$component] : array();
|
||||||
|
$componentObj = $this->getMock($componentClass, $methods, array($controllerObj->Components, $config));
|
||||||
$controllerObj->Components->set($name, $componentObj);
|
$controllerObj->Components->set($name, $componentObj);
|
||||||
$controllerObj->Components->enable($name);
|
$controllerObj->Components->enable($name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue