'Make laravel's unit tests to execute code inside AppServiceProvider::boot

Inside my AppServiceProvider::boot I am adding some methods to Laravel's Collection class. Then I am writting UnitTests to test these functionality, and execute these unit tests with ./artisan test MyTest

I have found that what laravel test command does is actually calls to vendor/bin/phpunit MyTest which doesn't load Laravel's service providers.

So the question is how do I make AppServiceProvider to be loaded when running unit tests?



Solution 1:[1]

./vendor/bin/phpunit calls all tests defined inside your phpunit.xml -> <testsuites>, your issue could be that you are using \PHPUnit\Framework\TestCase as your TestCase, in that case you are NOT loading the framework, so you just either use Test\TestCase or move your test to Feature and USE Test\TestCase

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matiaslauriti