PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Testing » PHPUnit2 » Bug #6820

generateMethodDefinition()

Details

Submitted2006-02-17 18:27 UTC
Frommaximilian dot gass at arcor dot de
Assignedsebastian
StatusClosed
PackagePHPUnit2
PHP VersionIrrelevant
Roadmaps(Not assigned)

Comments

[2006-02-17 18:27 UTC] maximilian dot gass at arcor dot de

Description:
------------
When generating a mock object I get the error message
below. It can easily fixed by replacing

$code .= $this->generateMethodDefinition($class, $method);

with

$code .= $this->generateMethodDefinition($method);

in
PHPUnit2_Extensions_MockObject_Mock::generateClassDefinition

Expected result:
----------------

Actual result:
--------------
Fatal error: Argument 1 passed to
PHPUnit2_Extensions_MockObject_Mock::generateMethodDefinition()
must be an instance of ReflectionMethod, called
in /usr/share/php/PHPUnit2/Extensions/MockObject/Mock.php
on line 173 and defined
in /usr/share/php/PHPUnit2/Extensions/MockObject/Mock.php
on line 199

0.1533 14.
PHPUnit2_Framework_Assert::getMock() /home/koolkaot/Phrecm/trunk/Kernel/Tests/ObservableTest.php:17
0.1534 15.
PHPUnit2_Extensions_MockObject_Mock::generate() /usr/share/php/PHPUnit2/Framework/Assert.php:968
0.1535 16.
PHPUnit2_Extensions_MockObject_Mock->generateClass() /usr/share/php/PHPUnit2/Extensions/MockObject/Mock.php:120
0.1539 17.
PHPUnit2_Extensions_MockObject_Mock->generateClassDefinition() /usr/share/php/PHPUnit2/Extensions/MockObject/Mock.php:139
0.1541 18.
PHPUnit2_Extensions_MockObject_Mock->generateMethodDefinition() /usr/share/php/PHPUnit2/Extensions/MockObject/Mock.php:173

[2006-02-17 18:59 UTC] sebastian at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.

[2006-02-17 20:05 UTC] maximilian dot gass at arcor dot de

Whoops, I've got it wrong! :-/ Sorry

generateMethodDefintion() seems to need the ReflectionClass
object. Therefore to fix this problem, you'll have to add
$class to the argument list of generateMethodDefinition()
instead of removing if from the calling statement.

Sorry.

[2006-02-17 20:20 UTC] maximilian dot gass at arcor dot de

I've just found how to create diffs with CVS so here's the
complete fix:

--- PHPUnit2/Extensions/MockObject/Mock.php 17 Feb 2006
18:59:12 -0000 1.15
+++ PHPUnit2/Extensions/MockObject/Mock.php 17 Feb 2006
20:18:48 -0000
@@ -170,7 +170,7 @@
continue;
}

- $code .=
$this->generateMethodDefinition($method);
+ $code .=
$this->generateMethodDefinition($class, $method);
}

$code .= "}\n";
@@ -196,7 +196,7 @@
return in_array($method->getName(),
$this->methods);
}

- protected function
generateMethodDefinition(ReflectionMethod $method)
+ protected function
generateMethodDefinition(ReflectionClass $class,
ReflectionMethod $method)
{
$code = "\n ";

@@ -234,7 +234,7 @@

$method->getName(),
$this->generateMethodParameters($method),
- var_export($method->getClass()->getName(),
TRUE),
+ var_export($class->getName(), TRUE),
var_export($method->getName(), TRUE)
);

[2006-02-17 21:18 UTC] sebastian at php dot net

Thank you for taking the time to write to us, but this is not
a bug.

The generateMethodDefinition() method has been refactored to only need the $method parameter as $class can be gained through $method->getClass().

[2006-02-17 21:29 UTC] maximilian dot gass at arcor dot de

I've just had a look at the PHP Manual and the method is
named 'getDeclaringClass'.

I just posted the patch because the CVS version didn't
work.

[2006-02-18 06:31 UTC] sebastian at php dot net

This bug has been fixed in CVS.

If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.