Skip to content

Commit f5055bd

Browse files
authored
Merge pull request #16 from hendrikheil/main
Add support for parallel testing
2 parents fe081d0 + ce2d7b8 commit f5055bd

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

.github/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ uses(FastRefreshDatabase::class)->in('Feature');
5959

6060
## Deleting The Migration Checksum
6161

62-
Sometimes you may wish to force-update database migrations, to do this, locate the `migrationChecksum.txt` file within `storage/app`.
62+
Sometimes you may wish to force-update database migrations, to do this, locate the `migration-checksum_{Database Name Slug}.txt` file within `storage/app`.
6363

6464
## Customising the checksum file location
6565

@@ -71,9 +71,7 @@ protected function getMigrationChecksumFile(): string
7171
return storage_path('custom/some-other-file.txt');
7272
}
7373
```
74-
75-
## Known Issues
7674

7775
### ParaTest Databases
7876

79-
The trait is unaware of what database or environment your tests are running within. Sometimes when running a parallel test after running individual tests, the migration checksum file may not have been deleted. You may have to manually delete the checksum file before running parallel tests.
77+
Parallel testing databases contain tokens that serve as unique identifiers for each test runner. This makes the trait inherently able to support parallel testing without any extra effort, because the database name is stored in the checksum file name.

src/Traits/FastRefreshDatabase.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use SplFileInfo;
66
use Symfony\Component\Finder\Finder;
77
use Symfony\Component\Process\Process;
8+
use Illuminate\Database\ConnectionInterface;
9+
use Illuminate\Support\Str;
810
use Illuminate\Contracts\Console\Kernel;
911
use Illuminate\Foundation\Testing\RefreshDatabase;
1012
use Illuminate\Foundation\Testing\RefreshDatabaseState;
@@ -103,6 +105,10 @@ protected function storeMigrationChecksum(string $checksum): void
103105
*/
104106
protected function getMigrationChecksumFile(): string
105107
{
106-
return storage_path('app/migrationChecksum.txt');
108+
$connection = $this->app[ConnectionInterface::class];
109+
110+
$databaseNameSlug = Str::slug($connection->getDatabaseName());
111+
112+
return storage_path("app/migration-checksum_{$databaseNameSlug}.txt");
107113
}
108114
}

tests/Pest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
*/
1313

1414

15-
use Plannrc\LaravelFastRefreshDatabase\Traits\FastRefreshDatabase;
15+
use Plannr\Laravel\FastRefreshDatabase\Traits\FastRefreshDatabase;
1616

1717
uses(FastRefreshDatabase::class)->in(__DIR__);

0 commit comments

Comments
 (0)