talyssonoc / react-laravel

Package for using ReactJS with Laravel
895 stars 90 forks source link

Error when running tests that contain @react_component directive #46

Open josh-taylor opened 8 years ago

josh-taylor commented 8 years ago

I'm getting an error that ../vendor/autoload.php could not be found when running phpunit on a page that contains the @react_component directive.

Stack trace:

Warning: Uncaught exception 'ErrorException' with message 'require_once(../vendor/autoload.php): failed to open stream: No such file or directory' in /Users/joshtaylor/Websites/----/vendor/talyssonoc/react-laravel/lib/React.php:5
Stack trace:
#0 /Users/joshtaylor/Websites/----/vendor/talyssonoc/react-laravel/lib/React.php(5): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'require_once(.....', '/Users/joshtayl...', 5, Array)
#1 /Users/joshtaylor/Websites/----/vendor/talyssonoc/react-laravel/lib/React.php(5): require_once()
#2 /Users/joshtaylor/Websites/----/vendor/composer/ClassLoader.php(412): include('/Users/joshtayl...')
#3 /Users/joshtaylor/Websites/----/vendor/composer/ClassLoader.php(301): Composer\Autoload\includeFile('/Users/joshtayl...')
#4 [internal function]: Composer\Autoload\ClassLoader->loadClass('React\\React')
#5 /Users/joshtaylor/Websites/----/vendor/talyssonoc/react-lara in /Users/joshtaylor/Websites/----/vendor/talyssonoc/react-laravel/lib/React.php on line 5
talyssonoc commented 8 years ago

Try to define a ENVIRONMENT constant with the value teste (like this: https://github.com/talyssonoc/react-laravel/blob/master/phpunit.php#L7), I guess I forgot the case where a test is running but this constant does not exist.

If it solves, a PR that solves this would be welcome :smile:

josh-taylor commented 8 years ago

I have solved it for now adding <const name="ENVIRONMENT" value="test"/> in my phpunit.xml file. Seems a bit redundant having set APP_ENV=testing in there also.

Would it make more sense to use a similar sort of thing as Laravel does so it doesn't need to be declared twice? If so, I could maybe start looking at a PR over the weekend for this?

talyssonoc commented 8 years ago

I guess we could use APP_ENV then, and read it with $_ENV (but it's also important to remember that the user might be testing with Behat or another test tool, maybe we should check if the same env var with the same value is exported for them too).

For as Laravel does you mean using the env var or something else?