Skip to content

Commit ff8f1f7

Browse files
committed
beforeRefreshParallelPhyiscalDatabaseCallbacks
1 parent 0bdd91e commit ff8f1f7

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
12+
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
1313
stability: [ prefer-stable ]
1414

1515
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

src/Tests/Concerns/WithParallelPhyiscalDatabase.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ trait WithParallelPhyiscalDatabase
1919

2020
private $parallelDatabaseName = 'laravel-parallel';
2121

22+
private $beforeRefreshParallelPhyiscalDatabaseCallbacks = [];
23+
2224
public function useParallelPhyiscalDatabase(): void
2325
{
2426
$this->setParallelPhyiscalDatabase();
27+
$this->callBeforeRefreshParallelPhyiscalDatabase();
2528
$this->refreshParallelPhyiscalDatabase();
2629
$this->bindParallelRequest();
2730
}
@@ -47,6 +50,13 @@ protected function setParallelPhyiscalDatabase(): void
4750
File::put(config('database.connections.'.$this->parallelDatabaseName.'.database'), '');
4851
}
4952

53+
protected function beforeRefreshParallelPhyiscalDatabase($callback): self
54+
{
55+
$this->beforeRefreshParallelPhyiscalDatabaseCallbacks[] = $callback;
56+
57+
return $this;
58+
}
59+
5060
protected function refreshParallelPhyiscalDatabase(): void
5161
{
5262
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
@@ -87,4 +97,11 @@ protected function usingPhyiscalDatabase(): bool
8797

8898
return config("database.connections.$default.database") !== ':memory:';
8999
}
100+
101+
private function callBeforeRefreshParallelPhyiscalDatabase(): void
102+
{
103+
foreach ($this->beforeRefreshParallelPhyiscalDatabaseCallbacks as $callback) {
104+
$callback();
105+
}
106+
}
90107
}

tests/Fixtures/setupDatabase.php renamed to tests/Fixtures/SetupDatabase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Support\Facades\Hash;
66

7-
trait setupDatabase
7+
trait SetupDatabase
88
{
99
protected function databaseSetUp($app)
1010
{

tests/Fixtures/artisan

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Session;
77
use Orchestra\Testbench\Concerns\CreatesApplication;
88
use Orchestra\Testbench\Concerns\HandlesRoutes;
99
use Recca0120\LaravelParallel\Console\ParallelCommand;
10-
use Recca0120\LaravelParallel\Tests\Fixtures\setupDatabase;
10+
use Recca0120\LaravelParallel\Tests\Fixtures\SetupDatabase;
1111
use Symfony\Component\Console\Application;
1212
use Symfony\Component\Console\Command\Command;
1313
use Symfony\Component\Console\Input\InputArgument;
@@ -18,7 +18,7 @@ require_once __DIR__.'/../../vendor/autoload.php';
1818

1919
$laravel = new class() {
2020
use CreatesApplication;
21-
use setupDatabase;
21+
use SetupDatabase;
2222
use HandlesRoutes;
2323

2424
private $app;

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
use Illuminate\Support\Facades\Auth;
99
use Orchestra\Testbench\TestCase as BaseTestCase;
1010
use Recca0120\LaravelParallel\ParallelServiceProvider;
11-
use Recca0120\LaravelParallel\Tests\Fixtures\setupDatabase;
11+
use Recca0120\LaravelParallel\Tests\Fixtures\SetupDatabase;
1212

1313
class TestCase extends BaseTestCase
1414
{
15-
use setupDatabase;
15+
use SetupDatabase;
1616

1717
protected function getEnvironmentSetUp($app)
1818
{

0 commit comments

Comments
 (0)