improved code style

This commit is contained in:
Val Bancer 2017-07-18 22:31:28 +02:00
parent 15f0fe31b1
commit 5e92034ad8

View file

@ -737,25 +737,14 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
* to disable the call to the original class' clone constructor. * to disable the call to the original class' clone constructor.
* @param bool $callAutoload The seventh (optional) parameter can be used to * @param bool $callAutoload The seventh (optional) parameter can be used to
* disable __autoload() during the generation of the test double class. * 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 * @return object
* @throws InvalidArgumentException When not supported parameters are set.
* @deprecated Use `getMockBuilder()` or `createMock()` in new unit tests. * @deprecated Use `getMockBuilder()` or `createMock()` in new unit tests.
* @see https://phpunit.de/manual/current/en/test-doubles.html * @see https://phpunit.de/manual/current/en/test-doubles.html
*/ */
public function getMock($originalClassName, $methods = array(), protected function _buildMock($originalClassName, $methods = array(),
array $arguments = array(), $mockClassName = '', array $arguments = array(), $mockClassName = '',
$callOriginalConstructor = true, $callOriginalClone = true, $callOriginalConstructor = true, $callOriginalClone = true,
$callAutoload = true, $cloneArguments = false, $callAutoload = true) {
$callOriginalMethods = false, $proxyTarget = null) {
$phpUnitVersion = PHPUnit_Runner_Version::id();
if ($phpUnitVersion < '5.7.0') {
return parent::getMock($originalClassName, $methods, $arguments,
$mockClassName, $callOriginalConstructor, $callOriginalClone,
$callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
}
$MockBuilder = $this->getMockBuilder($originalClassName); $MockBuilder = $this->getMockBuilder($originalClassName);
if (!empty($methods)) { if (!empty($methods)) {
$MockBuilder = $MockBuilder->setMethods($methods); $MockBuilder = $MockBuilder->setMethods($methods);
@ -775,6 +764,50 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
if ($callAutoload !== true) { if ($callAutoload !== true) {
$MockBuilder = $MockBuilder->disableAutoload(); $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) { if ($cloneArguments) {
throw new InvalidArgumentException('$cloneArguments parameter is not supported'); throw new InvalidArgumentException('$cloneArguments parameter is not supported');
} }
@ -784,7 +817,8 @@ abstract class CakeTestCase extends PHPUnit_Framework_TestCase {
if ($proxyTarget !== null) { if ($proxyTarget !== null) {
throw new InvalidArgumentException('$proxyTarget parameter is not supported'); throw new InvalidArgumentException('$proxyTarget parameter is not supported');
} }
return $MockBuilder->getMock(); return $this->_buildMock($originalClassName, $methods, $arguments,
$mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload);
} }
/** /**