mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Merge pull request #10912 from bancer/phpunit-5.7
adapter for the getMock() depricated in phpunit
This commit is contained in:
commit
b47e445c33
5 changed files with 110 additions and 27 deletions
|
@ -22,7 +22,7 @@
|
||||||
"ext-mcrypt": "*"
|
"ext-mcrypt": "*"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "3.7.*",
|
"phpunit/phpunit": "<6.0.0",
|
||||||
"cakephp/cakephp-codesniffer": "^1.0.0"
|
"cakephp/cakephp-codesniffer": "^1.0.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
|
|
@ -749,13 +749,10 @@ class ShellTest extends CakeTestCase {
|
||||||
public function testRunCommandBaseclassMethod() {
|
public function testRunCommandBaseclassMethod() {
|
||||||
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
|
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
|
||||||
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
||||||
|
|
||||||
$Parser->expects($this->once())->method('help');
|
$Parser->expects($this->once())->method('help');
|
||||||
$Mock->expects($this->once())->method('getOptionParser')
|
$Mock->expects($this->once())->method('getOptionParser')
|
||||||
->will($this->returnValue($Parser));
|
->will($this->returnValue($Parser));
|
||||||
$Mock->expects($this->never())->method('hr');
|
|
||||||
$Mock->expects($this->once())->method('out');
|
$Mock->expects($this->once())->method('out');
|
||||||
|
|
||||||
$Mock->runCommand('hr', array());
|
$Mock->runCommand('hr', array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -767,13 +764,10 @@ class ShellTest extends CakeTestCase {
|
||||||
public function testRunCommandMissingMethod() {
|
public function testRunCommandMissingMethod() {
|
||||||
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
|
$Mock = $this->getMock('Shell', array('startup', 'getOptionParser', 'out'), array(), '', false);
|
||||||
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
$Parser = $this->getMock('ConsoleOptionParser', array(), array(), '', false);
|
||||||
|
|
||||||
$Parser->expects($this->once())->method('help');
|
$Parser->expects($this->once())->method('help');
|
||||||
$Mock->expects($this->never())->method('idontexist');
|
|
||||||
$Mock->expects($this->once())->method('getOptionParser')
|
$Mock->expects($this->once())->method('getOptionParser')
|
||||||
->will($this->returnValue($Parser));
|
->will($this->returnValue($Parser));
|
||||||
$Mock->expects($this->once())->method('out');
|
$Mock->expects($this->once())->method('out');
|
||||||
|
|
||||||
$result = $Mock->runCommand('idontexist', array());
|
$result = $Mock->runCommand('idontexist', array());
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
}
|
}
|
||||||
|
@ -1029,31 +1023,27 @@ TEXT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that shell loggers do not get overridden in constructor if already configured
|
* Test that shell loggers do not get overridden in constructor if already configured
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testShellLoggersDoNotGetOverridden() {
|
public function testShellLoggersDoNotGetOverridden() {
|
||||||
$shell = $this->getMock(
|
$shell = $this->getMock(
|
||||||
"Shell", array(
|
"Shell", array(
|
||||||
"_loggerIsConfigured",
|
"_loggerIsConfigured",
|
||||||
"configureStdOutLogger",
|
"_configureStdOutLogger",
|
||||||
"configureStdErrLogger",
|
"_configureStdErrLogger",
|
||||||
),
|
),
|
||||||
array(),
|
array(),
|
||||||
"",
|
"",
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
|
||||||
$shell->expects($this->exactly(2))
|
$shell->expects($this->exactly(2))
|
||||||
->method("_loggerIsConfigured")
|
->method("_loggerIsConfigured")
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
$shell->expects($this->never())
|
$shell->expects($this->never())
|
||||||
->method("_configureStdOutLogger");
|
->method("_configureStdOutLogger");
|
||||||
|
|
||||||
$shell->expects($this->never())
|
$shell->expects($this->never())
|
||||||
->method("_configureStdErrLogger");
|
->method("_configureStdErrLogger");
|
||||||
|
|
||||||
$shell->__construct();
|
$shell->__construct();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -889,18 +889,12 @@ class DispatcherTest extends CakeTestCase {
|
||||||
'_clearBuffer',
|
'_clearBuffer',
|
||||||
'_flushBuffer'
|
'_flushBuffer'
|
||||||
));
|
));
|
||||||
|
|
||||||
$response->expects($this->never())
|
|
||||||
->method('body');
|
|
||||||
|
|
||||||
$response->expects($this->exactly(1))
|
$response->expects($this->exactly(1))
|
||||||
->method('_isActive')
|
->method('_isActive')
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
$Dispatcher->dispatch($request, $response);
|
$Dispatcher->dispatch($request, $response);
|
||||||
$result = ob_get_clean();
|
$result = ob_get_clean();
|
||||||
|
|
||||||
$this->assertEquals("/* this is the test asset css file */\n", $result);
|
$this->assertEquals("/* this is the test asset css file */\n", $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,13 +154,10 @@ class AssetDispatcherTest extends CakeTestCase {
|
||||||
|
|
||||||
$response = $this->getMock('CakeResponse', array('_sendHeader', 'checkNotModified'));
|
$response = $this->getMock('CakeResponse', array('_sendHeader', 'checkNotModified'));
|
||||||
$request = new CakeRequest('theme/test_theme/img/cake.power.gif');
|
$request = new CakeRequest('theme/test_theme/img/cake.power.gif');
|
||||||
|
|
||||||
$response->expects($this->once())->method('checkNotModified')
|
$response->expects($this->once())->method('checkNotModified')
|
||||||
->with($request)
|
->with($request)
|
||||||
->will($this->returnValue(true));
|
->will($this->returnValue(true));
|
||||||
$response->expects($this->never())->method('send');
|
|
||||||
$event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
|
$event = new CakeEvent('DispatcherTest', $this, compact('request', 'response'));
|
||||||
|
|
||||||
$this->assertSame($response, $filter->beforeDispatch($event));
|
$this->assertSame($response, $filter->beforeDispatch($event));
|
||||||
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
|
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
|
||||||
}
|
}
|
||||||
|
@ -193,13 +190,9 @@ class AssetDispatcherTest extends CakeTestCase {
|
||||||
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS),
|
||||||
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
|
||||||
), App::RESET);
|
), App::RESET);
|
||||||
|
|
||||||
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
$response = $this->getMock('CakeResponse', array('_sendHeader'));
|
||||||
$request = new CakeRequest('theme/test_theme/../../../../../../VERSION.txt');
|
$request = new CakeRequest('theme/test_theme/../../../../../../VERSION.txt');
|
||||||
$event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
|
$event = new CakeEvent('Dispatcher.beforeRequest', $this, compact('request', 'response'));
|
||||||
|
|
||||||
$response->expects($this->never())->method('send');
|
|
||||||
|
|
||||||
$filter = new AssetDispatcher();
|
$filter = new AssetDispatcher();
|
||||||
$this->assertNull($filter->beforeDispatch($event));
|
$this->assertNull($filter->beforeDispatch($event));
|
||||||
$this->assertFalse($event->isStopped());
|
$this->assertFalse($event->isStopped());
|
||||||
|
|
|
@ -715,6 +715,112 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
|
||||||
}
|
}
|
||||||
// @codingStandardsIgnoreEnd
|
// @codingStandardsIgnoreEnd
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a mock object for the specified class.
|
||||||
|
*
|
||||||
|
* @param string $originalClassName The class name of the object to be mocked.
|
||||||
|
* @param array $methods By default, all methods of the given class are replaced
|
||||||
|
* with a test double that just returns NULL unless a return value is configured
|
||||||
|
* using will($this->returnValue()), for instance.
|
||||||
|
* When the second (optional) parameter is provided, only the methods whose names
|
||||||
|
* are in the array are replaced with a configurable test double. The behavior
|
||||||
|
* of the other methods is not changed. Providing NULL as the parameter means
|
||||||
|
* that no methods will be replaced.
|
||||||
|
* @param array $arguments The third (optional) parameter may hold a parameter
|
||||||
|
* array that is passed to the original class' constructor (which is not replaced
|
||||||
|
* with a dummy implementation by default).
|
||||||
|
* @param string $mockClassName The fourth (optional) parameter can be used to
|
||||||
|
* specify a class name for the generated test double class.
|
||||||
|
* @param bool $callOriginalConstructor The fifth (optional) parameter can be
|
||||||
|
* used to disable the call to the original class' constructor.
|
||||||
|
* @param bool $callOriginalClone The sixth (optional) parameter can be used
|
||||||
|
* to disable the call to the original class' clone constructor.
|
||||||
|
* @param bool $callAutoload The seventh (optional) parameter can be used to
|
||||||
|
* disable __autoload() during the generation of the test double class.
|
||||||
|
* @return object
|
||||||
|
* @deprecated Use `getMockBuilder()` or `createMock()` in new unit tests.
|
||||||
|
* @see https://phpunit.de/manual/current/en/test-doubles.html
|
||||||
|
*/
|
||||||
|
protected function _buildMock($originalClassName, $methods = array(),
|
||||||
|
array $arguments = array(), $mockClassName = '',
|
||||||
|
$callOriginalConstructor = true, $callOriginalClone = true,
|
||||||
|
$callAutoload = true) {
|
||||||
|
$MockBuilder = $this->getMockBuilder($originalClassName);
|
||||||
|
if (!empty($methods)) {
|
||||||
|
$MockBuilder = $MockBuilder->setMethods($methods);
|
||||||
|
}
|
||||||
|
if (!empty($arguments)) {
|
||||||
|
$MockBuilder = $MockBuilder->setConstructorArgs($arguments);
|
||||||
|
}
|
||||||
|
if ($mockClassName != '') {
|
||||||
|
$MockBuilder = $MockBuilder->setMockClassName($mockClassName);
|
||||||
|
}
|
||||||
|
if ($callOriginalConstructor !== true) {
|
||||||
|
$MockBuilder = $MockBuilder->disableOriginalConstructor();
|
||||||
|
}
|
||||||
|
if ($callOriginalClone !== true) {
|
||||||
|
$MockBuilder = $MockBuilder->disableOriginalClone();
|
||||||
|
}
|
||||||
|
if ($callAutoload !== true) {
|
||||||
|
$MockBuilder = $MockBuilder->disableAutoload();
|
||||||
|
}
|
||||||
|
return $MockBuilder->getMock();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a mock object for the specified class.
|
||||||
|
*
|
||||||
|
* @param string $originalClassName The class name of the object to be mocked.
|
||||||
|
* @param array $methods By default, all methods of the given class are replaced
|
||||||
|
* with a test double that just returns NULL unless a return value is configured
|
||||||
|
* using will($this->returnValue()), for instance.
|
||||||
|
* When the second (optional) parameter is provided, only the methods whose names
|
||||||
|
* are in the array are replaced with a configurable test double. The behavior
|
||||||
|
* of the other methods is not changed. Providing NULL as the parameter means
|
||||||
|
* that no methods will be replaced.
|
||||||
|
* @param array $arguments The third (optional) parameter may hold a parameter
|
||||||
|
* array that is passed to the original class' constructor (which is not replaced
|
||||||
|
* with a dummy implementation by default).
|
||||||
|
* @param string $mockClassName The fourth (optional) parameter can be used to
|
||||||
|
* specify a class name for the generated test double class.
|
||||||
|
* @param bool $callOriginalConstructor The fifth (optional) parameter can be
|
||||||
|
* used to disable the call to the original class' constructor.
|
||||||
|
* @param bool $callOriginalClone The sixth (optional) parameter can be used
|
||||||
|
* to disable the call to the original class' clone constructor.
|
||||||
|
* @param bool $callAutoload The seventh (optional) parameter can be used to
|
||||||
|
* disable __autoload() during the generation of the test double class.
|
||||||
|
* @param bool $cloneArguments Not supported.
|
||||||
|
* @param bool $callOriginalMethods Not supported.
|
||||||
|
* @param string $proxyTarget Not supported.
|
||||||
|
* @return object
|
||||||
|
* @throws InvalidArgumentException When not supported parameters are set.
|
||||||
|
* @deprecated Use `getMockBuilder()` or `createMock()` in new unit tests.
|
||||||
|
* @see https://phpunit.de/manual/current/en/test-doubles.html
|
||||||
|
*/
|
||||||
|
public function getMock($originalClassName, $methods = array(),
|
||||||
|
array $arguments = array(), $mockClassName = '',
|
||||||
|
$callOriginalConstructor = true, $callOriginalClone = true,
|
||||||
|
$callAutoload = true, $cloneArguments = false,
|
||||||
|
$callOriginalMethods = false, $proxyTarget = null) {
|
||||||
|
$phpUnitVersion = PHPUnit_Runner_Version::id();
|
||||||
|
if (version_compare($phpUnitVersion, '5.7.0', '<')) {
|
||||||
|
return parent::getMock($originalClassName, $methods, $arguments,
|
||||||
|
$mockClassName, $callOriginalConstructor, $callOriginalClone,
|
||||||
|
$callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
|
||||||
|
}
|
||||||
|
if ($cloneArguments) {
|
||||||
|
throw new InvalidArgumentException('$cloneArguments parameter is not supported');
|
||||||
|
}
|
||||||
|
if ($callOriginalMethods) {
|
||||||
|
throw new InvalidArgumentException('$callOriginalMethods parameter is not supported');
|
||||||
|
}
|
||||||
|
if ($proxyTarget !== null) {
|
||||||
|
throw new InvalidArgumentException('$proxyTarget parameter is not supported');
|
||||||
|
}
|
||||||
|
return $this->_buildMock($originalClassName, $methods, $arguments,
|
||||||
|
$mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mock a model, maintain fixtures and table association
|
* Mock a model, maintain fixtures and table association
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue