diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index e820f11..30bd8be 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -10,15 +10,32 @@ jobs: fail-fast: true matrix: php: [ "8.0", "8.1", "8.2", "8.3" ] - laravel: [ "8.0", "9.0", "10.0" ] + laravel: [ "8.0", "9.0", "10.0", "11.0" ] psql: [ "9", "10", "11", "12", "13", "14", "15" ] exclude: - laravel: "8.0" php: "8.3" + - laravel: "9.0" php: "8.3" + - laravel: "10.0" php: "8.0" + + - laravel: "11.0" + php: "8.0" + + - laravel: "11.0" + php: "8.1" + + - laravel: "11.0" + psql: "9" + + - laravel: "11.0" + psql: "10" + + - laravel: "11.0" + psql: "11" name: php ${{ matrix.php }}, lr ${{ matrix.laravel }}, pg ${{ matrix.psql }} @@ -50,7 +67,7 @@ jobs: with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql - coverage: none + coverage: xdebug - name: Install dependencies run: composer require --dev laravel/framework:^${{ matrix.laravel }} diff --git a/README.md b/README.md index 8ad83bb..2c296f9 100644 --- a/README.md +++ b/README.md @@ -33,9 +33,17 @@ Or manually update `require-dev` block of `composer.json` and run `composer upda | Service | Versions | |:----------|:-----------------------------------| | PHP | ^8.0 | -| Laravel | ^8.0, ^9.0, ^10.0 | +| Laravel | ^8.0, ^9.0, ^10.0, ^11.0 | | Databases | MySQL 5.7+, PostgreSQL 9.5+, MSSQL | +| Laravel \ PostgreSQL | 9 | 10 | 11 | 12 | 13 | 14 | 15 | +|:---------------------|----|----|----|----|----|----|----| +| 8 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| 9 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| 10 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | +| 11 | ✖️ | ✖️ | ✖️ | ✅ | ✅ | ✅ | ✅ | + + ## Usage Create a new database and set up both connections in the `connections` section of diff --git a/composer.json b/composer.json index 0c2e590..71562f4 100644 --- a/composer.json +++ b/composer.json @@ -44,16 +44,16 @@ "doctrine/dbal": "^3.0", "dragon-code/contracts": "^2.15", "dragon-code/support": "^6.0", - "illuminate/contracts": "^8.0 || ^9.0 || ^10.0", - "illuminate/database": "^8.0 || ^9.0 || ^10.0", - "illuminate/support": "^8.0 || ^9.0 || ^10.0" + "illuminate/contracts": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/database": "^8.0 || ^9.0 || ^10.0 || ^11.0", + "illuminate/support": "^8.0 || ^9.0 || ^10.0 || ^11.0" }, "require-dev": { "ext-pdo_mysql": "*", "ext-pdo_pgsql": "*", "mockery/mockery": "^1.0", - "orchestra/testbench": "^6.0 || ^7.0 || ^8.0", - "phpunit/phpunit": "^9.6" + "orchestra/testbench": "^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^9.6 || ^10.0" }, "minimum-stability": "stable", "prefer-stable": true, diff --git a/phpunit.xml b/phpunit.xml index b89079c..6317452 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,8 +7,8 @@ bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" - convertNoticesToExceptions="true" - convertWarningsToExceptions="true" + convertNoticesToExceptions="false" + convertWarningsToExceptions="false" processIsolation="false" stopOnError="false" stopOnFailure="false" diff --git a/src/Console/Migrate.php b/src/Console/Migrate.php index 9d489f5..8d8da7c 100644 --- a/src/Console/Migrate.php +++ b/src/Console/Migrate.php @@ -23,10 +23,10 @@ class Migrate extends Command protected $description = 'Data transfer from one database to another'; - /** @var \DragonCode\Contracts\MigrateDB\Builder */ + /** @var Builder */ protected $source; - /** @var \DragonCode\Contracts\MigrateDB\Builder */ + /** @var Builder */ protected $target; /** @var array */ diff --git a/src/Database/Builder.php b/src/Database/Builder.php index 3e94c32..e89f0a7 100644 --- a/src/Database/Builder.php +++ b/src/Database/Builder.php @@ -13,7 +13,7 @@ abstract class Builder implements BuilderContract { use Makeable; - /** @var \Illuminate\Database\Connection */ + /** @var Connection */ protected $connection; abstract protected function tableNameColumn(): string; @@ -33,7 +33,9 @@ public function schema(): SchemaBuilder public function getAllTables(): array { - $tables = $this->schema()->getAllTables(); + $tables = method_exists($this->schema(), 'getAllTables') + ? $this->schema()->getAllTables() + : $this->schema()->getTables(); $key = $this->tableNameColumn(); @@ -69,15 +71,17 @@ protected function columns(string $table): array protected function filteredTables(array $tables, string $key): array { - return array_filter($tables, static function (stdClass $table) use ($key) { - return $table->{$key} !== 'migrations'; + return array_filter($tables, static function (array|stdClass $table) use ($key) { + $name = is_array($table) ? $table['name'] : $table->{$key}; + + return $name !== 'migrations'; }); } protected function pluckTableNames(array $tables, string $key): array { - return array_map(static function ($table) use ($key) { - return $table->{$key}; + return array_map(static function (array|stdClass $table) use ($key) { + return is_array($table) ? $table['name'] : $table->{$key}; }, $tables); } diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 3966501..805dbbc 100644 --- a/tests/Concerns/Database.php +++ b/tests/Concerns/Database.php @@ -3,6 +3,7 @@ namespace Tests\Concerns; use DragonCode\MigrateDB\Constants\Drivers; +use Illuminate\Database\Schema\Builder as SchemaBuilder; use Illuminate\Support\Facades\Config; use Tests\Configurations\BaseConfiguration; use Tests\Configurations\Manager; @@ -16,27 +17,27 @@ trait Database use HasUuidAndUlid; use Seeders; - protected $connectors = [ + protected array $connectors = [ Drivers::MYSQL => MySqlConnection::class, Drivers::POSTGRES => PostgresConnection::class, Drivers::SQL_SERVER => SqlServerConnection::class, ]; - protected $table_foo = 'foo'; + protected string $table_foo = 'foo'; - protected $table_bar = 'bar'; + protected string $table_bar = 'bar'; - protected $table_baz = 'baz'; + protected string $table_baz = 'baz'; - protected $table_ulid = 'ulid_table'; + protected string $table_ulid = 'ulid_table'; - protected $table_uuid = 'uuid_table'; + protected string $table_uuid = 'uuid_table'; - protected $choice_target = 'target'; + protected string $choice_target = 'target'; - protected $choice_source = 'source'; + protected string $choice_source = 'source'; - protected $choices = [ + protected array $choices = [ 'target', 'source', 'none', @@ -97,4 +98,11 @@ protected function runMigrations(): void { $this->artisan('migrate', ['--database' => $this->source_connection])->run(); } + + protected function getTables(SchemaBuilder $builder): array + { + return method_exists($builder, 'getAllTables') + ? $builder->getAllTables() + : $builder->getTables(); + } } diff --git a/tests/Connectors/BaseConnection.php b/tests/Connectors/BaseConnection.php index 88fe862..c6862dd 100644 --- a/tests/Connectors/BaseConnection.php +++ b/tests/Connectors/BaseConnection.php @@ -13,7 +13,7 @@ abstract class BaseConnection { use Makeable; - /** @var \Tests\Configurations\BaseConfiguration */ + /** @var BaseConfiguration */ protected $configuration; protected $default_database; diff --git a/tests/Unit/MysqlToMysqlTest.php b/tests/Unit/MysqlToMysqlTest.php index a750779..376e03d 100644 --- a/tests/Unit/MysqlToMysqlTest.php +++ b/tests/Unit/MysqlToMysqlTest.php @@ -12,8 +12,8 @@ class MysqlToMysqlTest extends TestCase { public function testFillable() { - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertEmpty($this->getTables($this->targetConnection())); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -26,8 +26,8 @@ public function testFillable() ->assertExitCode(0) ->run(); - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertNotEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertNotEmpty($this->getTables($this->targetConnection())); } public function testCount() diff --git a/tests/Unit/MysqlToPostgresTest.php b/tests/Unit/MysqlToPostgresTest.php index 094ef7d..69db540 100644 --- a/tests/Unit/MysqlToPostgresTest.php +++ b/tests/Unit/MysqlToPostgresTest.php @@ -12,8 +12,8 @@ class MysqlToPostgresTest extends TestCase { public function testFillable() { - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertEmpty($this->getTables($this->targetConnection())); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -26,8 +26,8 @@ public function testFillable() ->assertExitCode(0) ->run(); - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertNotEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertNotEmpty($this->getTables($this->targetConnection())); } public function testCount() diff --git a/tests/Unit/PostgresToMysqlTest.php b/tests/Unit/PostgresToMysqlTest.php index e5809c9..bcb2faf 100644 --- a/tests/Unit/PostgresToMysqlTest.php +++ b/tests/Unit/PostgresToMysqlTest.php @@ -12,8 +12,8 @@ class PostgresToMysqlTest extends TestCase { public function testFillable() { - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertEmpty($this->getTables($this->targetConnection())); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -26,8 +26,8 @@ public function testFillable() ->assertExitCode(0) ->run(); - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertNotEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertNotEmpty($this->getTables($this->targetConnection())); } public function testCount() diff --git a/tests/Unit/PostgresToPostgresTest.php b/tests/Unit/PostgresToPostgresTest.php index 8ec81ba..1a659f4 100644 --- a/tests/Unit/PostgresToPostgresTest.php +++ b/tests/Unit/PostgresToPostgresTest.php @@ -12,8 +12,8 @@ class PostgresToPostgresTest extends TestCase { public function testFillable() { - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertEmpty($this->getTables($this->targetConnection())); $this->artisan('db:migrate', [ '--schema-from' => $this->source_connection, @@ -26,8 +26,8 @@ public function testFillable() ->assertExitCode(0) ->run(); - $this->assertNotEmpty($this->sourceConnection()->getAllTables()); - $this->assertNotEmpty($this->targetConnection()->getAllTables()); + $this->assertNotEmpty($this->getTables($this->sourceConnection())); + $this->assertNotEmpty($this->getTables($this->targetConnection())); } public function testCount()