|
From: Aaron C. <aar...@un...> - 2009-10-06 23:20:28
|
Hi, I've recently started converting some old php4 libraries to php5.
I've noticed that we have in the past taken liberties with php4 and
simple-tests. A lot of my time has been spent converting test cases and
learning new pitfalls, one such, is causing confusion.
I in the past we have written test cases on the method level. Each
method had a test case, each call from within the tested method to
another method was a call to a mocked method. e.g.
class thing {
public function something() {
$somethingElseValue = $this->somethingElse(); <-- this will be mocked
...
}
public function somethingElse() {
return 'something else';
}
}
I guess you may call this white-box testing, it allows for fine grain
control and test cases which are quite independent of each other.
The problem is when it comes to mocking private methods. Using the
example above: if the method /somethingElse/ is private, then it seems
that it is no longer possible to mock the method e.g.
class thing {
public function something() {
$somethingElseValue = $this->somethingElse(); <-- this will be mocked
...
}
private function somethingElse() {
return 'somethingElse';
}
}
...
$returnReference = 'Bunny';
$partiallyMockedThing->setReturnReference('somethingElse',
$returnReference);
In this second example the /somethingElse/ method is private, mocking
the method and then running the test case will result in the variable
/$somethingElseValue /having the string value of /something else
/instead of /Bunny/. In my experimentation I have found that: If I were
to change the somethingElse method to public again, then the
/$somethingElseValue/ would then have the string value of /Bunny
/instead of /something else/
I'm assuming that my understanding of test cases is limited and that I'm
approaching this the wrong way, I would appreciate any clarification in
this matter?
There is always a little glimmer of hope that let's me hold on to the
possibility that this is not intended functionality and I don't have to
re-write most of our test cases!
FYI:
PHP 5.2.6-3ubuntu4.2 with Suhosin-Patch 0.9.6.2 (cli) (built: Aug 21
2009 21:43:13)
Simpletest 1.0.1
Thanks for your time
Aaron
--
Please sponsor my team and I for the Sydney to Wollongong Ride on Noverber the 1st 2009!
http://register.gongride.org.au/?aaronchilcott
Donations over $65 get a free autographed photograph!
|