From f984511ff728ced4e9b0de5bd6ce03ec591c57aa Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Fri, 15 Mar 2024 02:28:15 +0300 Subject: [PATCH] Fixed deprecated methods in the Laravel 11 --- src/Database/Builder.php | 4 +++- tests/Concerns/Database.php | 26 +++++++++++++++++--------- tests/Unit/MysqlToMysqlTest.php | 8 ++++---- tests/Unit/MysqlToPostgresTest.php | 8 ++++---- tests/Unit/PostgresToMysqlTest.php | 8 ++++---- tests/Unit/PostgresToPostgresTest.php | 8 ++++---- 6 files changed, 36 insertions(+), 26 deletions(-) diff --git a/src/Database/Builder.php b/src/Database/Builder.php index 6b07586..19b27ff 100644 --- a/src/Database/Builder.php +++ b/src/Database/Builder.php @@ -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(); diff --git a/tests/Concerns/Database.php b/tests/Concerns/Database.php index 3966501..af49361 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/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()