Skip to content
Permalink
Browse files

improved code style

  • Loading branch information...
bancer committed Jul 18, 2017
1 parent 15f0fe3 commit 5e92034ad878d8c0fe08df98cbcdfa3e27ea9676
Showing with 48 additions and 14 deletions.
  1. +48 −14 lib/Cake/TestSuite/CakeTestCase.php
@@ -737,25 +737,14 @@ protected function skipUnless($condition, $message = '') {
* 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(),
protected function _buildMock($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 ($phpUnitVersion < '5.7.0') {
return parent::getMock($originalClassName, $methods, $arguments,
$mockClassName, $callOriginalConstructor, $callOriginalClone,
$callAutoload, $cloneArguments, $callOriginalMethods, $proxyTarget);
}
$callAutoload = true) {
$MockBuilder = $this->getMockBuilder($originalClassName);
if (!empty($methods)) {
$MockBuilder = $MockBuilder->setMethods($methods);
@@ -775,6 +764,50 @@ public function getMock($originalClassName, $methods = array(),
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');
}
@@ -784,7 +817,8 @@ public function getMock($originalClassName, $methods = array(),
if ($proxyTarget !== null) {
throw new InvalidArgumentException('$proxyTarget parameter is not supported');
}
return $MockBuilder->getMock();
return $this->_buildMock($originalClassName, $methods, $arguments,
$mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload);
}
/**

0 comments on commit 5e92034

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