I am using Pest library to write tests in laravel. I created the my-laravel-application/tests/Integration directory in laravel and defined a new test suite in phpunit.xml

<testsuite name="Integration">
   <directory suffix=".test.php">./tests/Integration</directory>
</testsuite>

So that laravel acknowledges the test files in Integration directory and I could write my integration tests in a separate directory with a proper name(Integration directory), And I put my test files in the my-laravel-application/tests/Integration directory and I got the following error while running php artisan test:

InvalidArgumentException - Unknown format "name"
vendor/fakerphp/faker/src/Faker/Generator.php:657

which indicates that the $this->faker->name() line of code in my UserFactory (I am using UserFactory class in my tests) has something wrong with, it says that name() method does not exist on $this->faker. But my tests used to work fine, before moving them to my-laravel-application/tests/Integration directory. What is the real problem and how can I fix this?

2

There are 2 answers

0
Ngaiza On

This thread saved me lots of time.

I made sure an using right test case in the entire test dir...

uses(Tests\TestCase::class)->in(__DIR__);
1
Gandalf On

I found the solution based on this answer. You should enforce the use of Tests\TestCase (instead of PHPUnit\Framework\TestCase) for all the tests written in your newly created directory (Integration directory) by adding the following code to /tests/Pest.test:

uses(Tests\TestCase::class)->in('Integration');