Running PHPUnit #1277

Closed
opened 2026-02-05 00:28:19 +03:00 by OVERLORD · 1 comment
Owner

Originally created by @jameswmcnab on GitHub (Jul 27, 2019).

Working on a PR and I want to run the tests, but I'm a bit confused as to how the development environment is configured.

I know the readme says not to run vendor/bin/phpunit and to download and run PHPUnit 6, but I'm a bit confused as to why?

I get the following error:

vendor/bin/phpunit
PHP Fatal error:  Cannot redeclare redirect() (previously declared in /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:658) in /Users/jameswmcnab/dev/jameswmcnab/BookStack/app/helpers.php on line 161
PHP Stack trace:
PHP   1. {main}() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/phpunit:53
PHP   3. PHPUnit\TextUI\Command->run() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:148
PHP   4. PHPUnit\TextUI\Command->handleArguments() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:159
PHP   5. PHPUnit\TextUI\Command->handleBootstrap() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:788
PHP   6. PHPUnit\Util\Fileloader::checkAndLoad() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:991
PHP   7. PHPUnit\Util\Fileloader::load() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/Util/Fileloader.php:48
PHP   8. include_once() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/Util/Fileloader.php:64

However just renaming that helper function seems to allow PHPUnit to run normally.

I've learnt the hard way that overriding core framework features like this always causes trouble.

Would you expect a PR that renames that helper function and it's usages within the app, and updates the readme to use the composer installed version of PHPUnit?

Originally created by @jameswmcnab on GitHub (Jul 27, 2019). Working on a PR and I want to run the tests, but I'm a bit confused as to how the development environment is configured. I know the readme says not to run `vendor/bin/phpunit` and to download and run PHPUnit 6, but I'm a bit confused as to why? I get the following error: ``` vendor/bin/phpunit PHP Fatal error: Cannot redeclare redirect() (previously declared in /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:658) in /Users/jameswmcnab/dev/jameswmcnab/BookStack/app/helpers.php on line 161 PHP Stack trace: PHP 1. {main}() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/phpunit:0 PHP 2. PHPUnit\TextUI\Command::main() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/phpunit:53 PHP 3. PHPUnit\TextUI\Command->run() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:148 PHP 4. PHPUnit\TextUI\Command->handleArguments() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:159 PHP 5. PHPUnit\TextUI\Command->handleBootstrap() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:788 PHP 6. PHPUnit\Util\Fileloader::checkAndLoad() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/TextUI/Command.php:991 PHP 7. PHPUnit\Util\Fileloader::load() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/Util/Fileloader.php:48 PHP 8. include_once() /Users/jameswmcnab/dev/jameswmcnab/BookStack/vendor/phpunit/phpunit/src/Util/Fileloader.php:64 ``` However just renaming that helper function seems to allow PHPUnit to run normally. I've learnt the hard way that overriding core framework features like this always causes trouble. Would you expect a PR that renames that helper function and it's usages within the app, and updates the readme to use the composer installed version of PHPUnit?
Author
Owner

@ssddanbrown commented on GitHub (Aug 4, 2019):

Yeah, I know it's a bit awkward.

Laravel does make it's helper functions override-able which would generally be fine but yeah, issues are thrown when using the composer provided phpunit. Between the phpunit options, the difference lies in how they use the composer auto-loader. The composer-provided phpunit uses the same autoloader as the BookStack app whereas a downloaded phpunit does not depend on local vendor files. The composer-provided phpunit causes the laravel helper functions to be parsed before the BookStack helper functions, therefore throwing this error.

I've been working on updating the BookStack URL system anyway, to extend the laravel URL generator so the original laravel helpers can be used as normal. I'll update the title of this and leave it open as a reminder to update the testing instructions and ensure phpunit can be ran via composer after I've made changes.

@ssddanbrown commented on GitHub (Aug 4, 2019): Yeah, I know it's a bit awkward. Laravel does make it's helper functions override-able which would generally be fine but yeah, issues are thrown when using the composer provided phpunit. Between the phpunit options, the difference lies in how they use the composer auto-loader. The composer-provided phpunit uses the same autoloader as the BookStack app whereas a downloaded phpunit does not depend on local vendor files. The composer-provided phpunit causes the laravel helper functions to be parsed before the BookStack helper functions, therefore throwing this error. I've been working on updating the BookStack URL system anyway, to extend the laravel URL generator so the original laravel helpers can be used as normal. I'll update the title of this and leave it open as a reminder to update the testing instructions and ensure phpunit can be ran via composer after I've made changes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#1277