The issue you're encountering is likely due to the way Pest handles the RefreshDatabase trait. In Laravel, the beforeRefreshingDatabase method is part of the RefreshDatabase trait, which is typically used in PHPUnit test cases. However, when using Pest, the trait might not be applied in the same way as it is in a standard PHPUnit setup.
Here are a few steps you can take to ensure that beforeRefreshingDatabase is called:
-
Ensure Proper Trait Usage: Make sure that the
RefreshDatabasetrait is correctly applied to your test case. In Pest, you might need to explicitly use the trait in your test case class. -
Check Pest Configuration: Verify that your Pest configuration is correctly set up to use the
TestCaseclass where theRefreshDatabasetrait is applied. -
Override the Method in the Correct Class: Ensure that the
beforeRefreshingDatabasemethod is overridden in the class that is actually using theRefreshDatabasetrait. If you're using Pest, you might need to create a custom test case class that extends fromIlluminate\Foundation\Testing\TestCaseand use this class in your Pest tests.
Here's an example of how you might set this up:
// CustomTestCase.php
namespace Tests;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class CustomTestCase extends BaseTestCase
{
use RefreshDatabase;
protected function beforeRefreshingDatabase()
{
Log::info(__METHOD__);
}
}
Then, in your Pest.php file, ensure you're using this custom test case:
uses(Tests\CustomTestCase::class)->in('Feature', 'Integration');
By ensuring that the beforeRefreshingDatabase method is in the correct context and that your Pest tests are using the right test case class, you should be able to see the expected log output.