Skip to content

Commit

Permalink
beforeRefreshParallelPhyiscalDatabaseCallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Feb 17, 2024
1 parent 0bdd91e commit ff8f1f7
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
stability: [ prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
17 changes: 17 additions & 0 deletions src/Tests/Concerns/WithParallelPhyiscalDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ trait WithParallelPhyiscalDatabase

private $parallelDatabaseName = 'laravel-parallel';

private $beforeRefreshParallelPhyiscalDatabaseCallbacks = [];

public function useParallelPhyiscalDatabase(): void
{
$this->setParallelPhyiscalDatabase();
$this->callBeforeRefreshParallelPhyiscalDatabase();
$this->refreshParallelPhyiscalDatabase();
$this->bindParallelRequest();
}
Expand All @@ -47,6 +50,13 @@ protected function setParallelPhyiscalDatabase(): void
File::put(config('database.connections.'.$this->parallelDatabaseName.'.database'), '');
}

protected function beforeRefreshParallelPhyiscalDatabase($callback): self
{
$this->beforeRefreshParallelPhyiscalDatabaseCallbacks[] = $callback;

return $this;
}

protected function refreshParallelPhyiscalDatabase(): void
{
$this->artisan('migrate:fresh', $this->migrateFreshUsing());
Expand Down Expand Up @@ -87,4 +97,11 @@ protected function usingPhyiscalDatabase(): bool

return config("database.connections.$default.database") !== ':memory:';
}

private function callBeforeRefreshParallelPhyiscalDatabase(): void
{
foreach ($this->beforeRefreshParallelPhyiscalDatabaseCallbacks as $callback) {
$callback();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Illuminate\Support\Facades\Hash;

trait setupDatabase
trait SetupDatabase
{
protected function databaseSetUp($app)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/artisan
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Session;
use Orchestra\Testbench\Concerns\CreatesApplication;
use Orchestra\Testbench\Concerns\HandlesRoutes;
use Recca0120\LaravelParallel\Console\ParallelCommand;
use Recca0120\LaravelParallel\Tests\Fixtures\setupDatabase;
use Recca0120\LaravelParallel\Tests\Fixtures\SetupDatabase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -18,7 +18,7 @@ require_once __DIR__.'/../../vendor/autoload.php';

$laravel = new class() {
use CreatesApplication;
use setupDatabase;
use SetupDatabase;
use HandlesRoutes;

private $app;
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use Illuminate\Support\Facades\Auth;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Recca0120\LaravelParallel\ParallelServiceProvider;
use Recca0120\LaravelParallel\Tests\Fixtures\setupDatabase;
use Recca0120\LaravelParallel\Tests\Fixtures\SetupDatabase;

class TestCase extends BaseTestCase
{
use setupDatabase;
use SetupDatabase;

protected function getEnvironmentSetUp($app)
{
Expand Down

0 comments on commit ff8f1f7

Please sign in to comment.