Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to instantiate ReflectionClass object w/ path that doesn't exist #802

Closed
veilig2000 opened this issue Jan 30, 2013 · 6 comments
Closed

Comments

@veilig2000
Copy link

PHPUnit_Util_GlobalState::phpunitFiles() is trying to call
self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Story_TestCase', 2);

and PHPUnit_Extensions_Story_TestCase does not exist.

phpunit --version
3.7.13

@edorian
Copy link
Contributor

edorian commented Jan 30, 2013

He,

thanks for the bug report.

Whats the error message you are getting and what are you trying to do when the error happens?

@veilig2000
Copy link
Author

NP.

Testing Magento modules using the EcomDev_PHPUnit module. Tried commenting
out the offending stmt and tests start running again.

phpunit --filter processOrderShouldFailGracefully
PHPUnit 3.7.13 by Sebastian Bergmann.

Configuration read from /var/www/server/bmodules/B/phpunit.xml.dist

EPHP Fatal error: Uncaught exception 'Exception' with message 'Warning:
include(PHPUnit/Extensions/Story/TestCase.php): failed to open stream: No
such file or directory in /var/www/server/bmodules/sites/
1.7.0.2/httpdocs/lib/Varien/Autoload.php on line 93' in
/var/www/server/bmodules/sites/
1.7.0.2/httpdocs/app/code/core/Mage/Core/functions.php:245
Stack trace:
#0 /var/www/server/bmodules/sites/
1.7.0.2/httpdocs/lib/Varien/Autoload.php(93): mageCoreErrorHandler(2,
'include(PHPUnit...', '/var/www/server...', 93, Array)
#1 /var/www/server/bmodules/sites/
1.7.0.2/httpdocs/lib/Varien/Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('PHPUnit_Extensi...')
#3 [internal function]: spl_autoload_call('PHPUnit_Extensi...')
#4 /usr/share/php/PHPUnit/Util/GlobalState.php(409):
class_exists('PHPUnit_Extensi...')
#5 /usr/share/php/PHPUnit/Util/GlobalState.php(395):
PHPUnit_Util_GlobalState::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensi...',
2)
#6 /usr/share/php/ in /var/www/server/bbmodules/sites/
1.7.0.2/httpdocs/app/code/core/Mage/Core/functions.php on line 245

Thanks,
Jamie K.

On Wed, Jan 30, 2013 at 3:51 PM, Volker Dusch [email protected]:

He,

thanks for the bug report.

Whats the error message you are getting and what are you trying to do when
the error happens?


Reply to this email directly or view it on GitHubhttps://github.com//issues/802#issuecomment-12911762.

@sebastianbergmann
Copy link
Owner

This is not a problem with PHPUnit but with the autoloader declared in Varien/Autoload.php.

@veilig2000
Copy link
Author

I'm a little confused how this is an issue w/ the autoloader in Varien/Autoload.php

Specifically I'm confused on why every other file that is called in the PHPUnit_Util_GlobalState::phpunitFiles() method exists in the file system except the call self::addDirectoryContainingClassToPHPUnitFilesList('PHPUnit_Extensions_Story_TestCase', 2);

I can clearly see when PHPUnit/Extensions/Story/TestCase.php existed in phpunit version 3.5, but I'm running phpunit 3.7.13 and the entire PHPUnit/Extensions/Story directory was removed in version 3.6

and when I comment out the the TestCase line, the call to class_exists($className) in PHPUnit_Util_GlobalState::addDirectoryContainingClassToPHPUnitFilesList doesn't get called, causing the defaulted 2nd parameter, autoload = true, to not fire the autoloader in Varien/Autoload.php which throws the correct Exception "failed to open stream: No such file or directory..."

@sebastianbergmann
Copy link
Owner

It is an issue with the autoloader declared in `Varien/Autoload.php' because that autoloader is trying to include a file that it is not responsible for.

The PHPUnit_Extensions_Story_TestCase class is not part of the main PHPUnit distribution anymore. It is distributed via the optional PHPUnit_Story package. If that package is installed, its autoloader is available and takes care of loading the PHPUnit_Extensions_Story_TestCase class. The error you are experiencing happens because a completely different autoloader thinks it is responsible for loading that class.

@cmuench
Copy link

cmuench commented May 1, 2013

@sebastianbergmann You are right. It's a problem with the Magento Autoloader and it's possible to unregister the autoloader during the tests. I did this in my project n98-magerun.

  1. Init Magento Mage::app()
  2. Unregister autoloader spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
  3. Register an own PSR-0 autoloader and add the Magento pathes.

I did this with Composer autoloader.

$loader = require __DIR__ . '/../vendor/autoload.php';
/* @var $loader \Composer\Autoload\ClassLoader */
$loader->setUseIncludePath(true);

$base = 'MAGENTO BASE DIR';
$paths = array(
    $base . '/app/code/local',
    $base . '/app/code/community',
    $base . '/app/code/core',
    $base . '/lib',
);
set_include_path(implode(PATH_SEPARATOR, $paths) . PATH_SEPARATOR . get_include_path());

@veilig2000
This is also a possible solution for EcomDev_PHPUnit. It's always the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants