From b2481dc8ffc23c4bcd4d0a3f8898eeb26c55284d Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Thu, 24 Oct 2024 20:34:02 +0400 Subject: [PATCH] Use `isReadonly()` method to detect that driver is readonly; add test --- src/Migrator.php | 2 +- .../Migrations/Unit/IsolatedMigratorTest.php | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/Migrations/Unit/IsolatedMigratorTest.php diff --git a/src/Migrator.php b/src/Migrator.php index df3245d..39e0e98 100644 --- a/src/Migrator.php +++ b/src/Migrator.php @@ -319,7 +319,7 @@ private function getDatabases(): iterable if ($this->dbal instanceof DatabaseManager) { return array_filter( $this->dbal->getDatabases(), - fn (DatabaseInterface $db): bool => !$db->getDriver()->getSchemaHandler() instanceof ReadonlyHandler + fn (DatabaseInterface $db): bool => !$db->getDriver()->isReadonly() ); } return []; diff --git a/tests/Migrations/Unit/IsolatedMigratorTest.php b/tests/Migrations/Unit/IsolatedMigratorTest.php new file mode 100644 index 0000000..a00d6d5 --- /dev/null +++ b/tests/Migrations/Unit/IsolatedMigratorTest.php @@ -0,0 +1,44 @@ +addDatabase( + new Database( + 'foo', + '', + $driver = $this->createMock(DriverInterface::class), + ), + ); + $driver->expects($this->atLeastOnce())->method('isReadonly')->willReturn(true); + $driver + ->expects($this->any()) + ->method($this->callback(fn($name) => $name !== 'isReadonly')) + ->willThrowException(new \RuntimeException('Unexpected method call')); + + $repository = $this->createMock(RepositoryInterface::class); + + $migrator = new Migrator( + new MigrationConfig([]), + $dbal, + $repository, + ); + + $migrator->isConfigured(); + } +}