Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Mocking/Cloning #25

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions PHPUnit/Framework/MockObject/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,14 @@ protected static function generateMock($originalClassName, $methods, $mockClassN
$cloneTemplate = $cloneTemplate->render();
}

$emptyInterfaceMethods = array();

if($isInterface && !empty($methods) && is_array($methods))
{
$emptyInterfaceMethods = $methods;
$methods = get_class_methods($mockClassName['fullClassName']);
}

if (is_array($methods) && empty($methods) &&
($isClass || $isInterface)) {
$methods = get_class_methods($mockClassName['fullClassName']);
Expand Down Expand Up @@ -469,7 +477,7 @@ protected static function generateMock($originalClassName, $methods, $mockClassN

if (self::canMockMethod($method)) {
$mockedMethods .= self::generateMockedMethodDefinitionFromExisting(
$templateDir, $method
$templateDir, $method, in_array($methodName, $emptyInterfaceMethods)
);
}
}
Expand Down Expand Up @@ -571,9 +579,10 @@ protected static function generateMockClassDeclaration(array $mockClassName, $is
/**
* @param string $templateDir
* @param ReflectionMethod $method
* @param boolean $empty
* @return string
*/
protected static function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method)
protected static function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method, $empty = FALSE)
{
if ($method->isPrivate()) {
$modifier = 'private';
Expand Down Expand Up @@ -606,7 +615,8 @@ protected static function generateMockedMethodDefinitionFromExisting($templateDi
$modifier,
PHPUnit_Util_Class::getMethodParameters($method),
$reference,
$static
$static,
$empty
);
}

Expand All @@ -618,18 +628,26 @@ protected static function generateMockedMethodDefinitionFromExisting($templateDi
* @param string $arguments
* @param string $reference
* @param boolean $static
* @param boolean $empty
* @return string
*/
protected static function generateMockedMethodDefinition($templateDir, $className, $methodName, $modifier = 'public', $arguments = '', $reference = '', $static = FALSE)
protected static function generateMockedMethodDefinition($templateDir, $className, $methodName, $modifier = 'public', $arguments = '', $reference = '', $static = FALSE, $empty = FALSE)
{
if ($static) {
$template = new Text_Template(
$templateDir . 'mocked_static_method.tpl'
);
} else {
$template = new Text_Template(
$templateDir . 'mocked_object_method.tpl'
);
if($empty===TRUE)
{
$template = new Text_Template(
$templateDir . 'mocked_object_empty_method.tpl'
);
} else {
$template = new Text_Template(
$templateDir . 'mocked_object_method.tpl'
);
}
}

$template->setVar(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{modifier} function {reference}{method_name}({arguments})
{

}