Closed ValterJunior closed 1 year ago
Actually, I just found my solution. Adding uses(Tests\TestCase::class)->in('Feature');
in the Pest.php
file instead of my own testing file did the trick. I don't know if that's mentioned in the documentation, but at least it wasn't that clear to me.
I will leave it here in case someone stumbles with the same issue.
Hello,
I have been trying to start using pest in an existing Laravel project, although already existing, still a small one. I started by following the library documentation and tried to migrate my first test to this new format. However, for some reason, pest won't properly instantiate the Faker object from my factory classes on Laravel.
Here is how the test looks like:
When running this test using 'sail pest' command (or 'php artisan pest'), I get the following error:
Comparing the behavior of both original (PHPUnit) and migrated (Pest) ones, I can see that at some point the base factory class from Laravel will try to instantiate the Faker generator class using the service container, and at this point, in the original process the
DatabaseServiceProvider
should be called which will then call the 'create' method of the Generator class, as you can see from the stack trace captured below:The same does not happen when running the factory with the new Pest test. For some reason, Laravel's container service does not call the
DatabaseServiceProvider
at the same point, which makes me wonder whether Laravel framework is being properly booted at all, in this case.Here is how the factory class looks like, in case you need more insight on that:
...and here is the
composer.json
library list. As you can see, I have bothpestphp/pest
andpestphp/pest-plugin-laravel
libraries installed.Any clue on what could be happening in here? Any tips are much appreciated.
Thanks, Valter