Skip to content

Commit

Permalink
improved code style
Browse files Browse the repository at this point in the history
  • Loading branch information
bancer committed Jul 18, 2017
1 parent 15f0fe3 commit 5e92034
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions lib/Cake/TestSuite/CakeTestCase.php
Expand Up @@ -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);
Expand All @@ -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');
}
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 5e92034

Please sign in to comment.