|
Monday 05 October 2009 4:00:46 pm
Comment54579
Hi again everyone, I've been trying on and off to successfully generate stub tests for an extension of mine, by following the instructions on ezpedia. But I kept getting the following error:
Warning: Invalid argument supplied for foreach() in /path/to/Exponential/sites/tests/toolkit/extras/scripts/create-test-from-class.php on line 78
So I traced the error back to an <b>extremely odd</b> assumption made in getClassName() in <b>ezptestrunner.php</b>:
static public function getClassName( $file )
{
...
$total = $size > 30 ? 30 : $size;
// check only the last 30 classes.
for ( $i = $size - 1; $i > $size - $total - 1; $i-- )
{
$rf = new ReflectionClass( $classes[$i] );
$len = strlen( $file );
if ( strcmp( $file, substr( $rf->getFileName(), -$len ) ) == 0 )
{
return $classes[$i];
}
}
...
What I think getClassName() does is to locate the class defined in the value of -s passed to <b>create-test-from-class.php</b> from the array returned by PHPs get_declared_classes(). However, while iterating through the array of classnames thus returned, getClassName() is only returning the last 30 classes. If I make ezptestrunner.php spit out <b>all</b> the classes returned by PHPs get_declared_classes(), then the one I'm after is in the first 100 or so of the total array. It's never going to be passed to getClass() in create-test-from-class.php becuase it's index is not in the last 30. Why does ezptestrunner.php do it this way? I have hacked my copy to return all it finds, I no longer receive the above error and my stub tests are generated (all 44 of them!) I guess there must be a reason for this, performance perhaps? Keen to hear your thoughts.
Cheers, Russell
Russell Michell, Wellington, New Zealand.
We're building! http://www.theruss.com/blog/
I'm on Twitter: http://twitter.com/therussdotcom
Believe nothing, consider everything.
|