From 8ad205023ff285eb143c440d9525171ad0b38b38 Mon Sep 17 00:00:00 2001 From: Louis Charette Date: Fri, 10 Nov 2023 16:10:20 -0500 Subject: [PATCH] Inject Connection instead of Database Manager --- app/src/Bakery/Helper/DatabaseTest.php | 8 +- app/src/Database/Migrator/Migrator.php | 57 ++++---------- app/src/ServicesProvider/DatabaseService.php | 6 +- .../Integration/Bakery/DebugCommandTest.php | 8 +- .../Database/Migrator/MigratorTest.php | 13 ++-- .../Migrator/MigratorDependencyTest.php | 19 +---- .../Migrator/MigratorRollbackTest.php | 44 ++--------- .../Unit/Database/Migrator/MigratorTest.php | 74 +++++-------------- 8 files changed, 59 insertions(+), 170 deletions(-) diff --git a/app/src/Bakery/Helper/DatabaseTest.php b/app/src/Bakery/Helper/DatabaseTest.php index 75c29ba8..bf24e55a 100644 --- a/app/src/Bakery/Helper/DatabaseTest.php +++ b/app/src/Bakery/Helper/DatabaseTest.php @@ -13,7 +13,7 @@ namespace UserFrosting\Sprinkle\Core\Bakery\Helper; use DI\Attribute\Inject; -use Illuminate\Database\Capsule\Manager as Capsule; +use Illuminate\Database\Connection; use PDOException; /** @@ -26,7 +26,7 @@ trait DatabaseTest { #[Inject] - protected Capsule $capsule; + protected Connection $connection; /** * Test database connection directly using PDO. @@ -37,9 +37,7 @@ trait DatabaseTest protected function testDB(): bool { try { - $connectionName = $this->capsule->getDatabaseManager()->getDefaultConnection(); - $connection = $this->capsule->getConnection($connectionName); - $connection->getPdo(); + $this->connection->getPdo(); } catch (PDOException $e) { $message = 'Could not connect to the database connection' . PHP_EOL; $message .= 'Exception: ' . $e->getMessage() . PHP_EOL . PHP_EOL; diff --git a/app/src/Database/Migrator/Migrator.php b/app/src/Database/Migrator/Migrator.php index 30b83f6c..8188f2b9 100644 --- a/app/src/Database/Migrator/Migrator.php +++ b/app/src/Database/Migrator/Migrator.php @@ -12,9 +12,7 @@ namespace UserFrosting\Sprinkle\Core\Database\Migrator; -use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Connection; -use Illuminate\Database\Schema\Grammars\Grammar; use UserFrosting\Sprinkle\Core\Exceptions\MigrationDependencyNotMetException; use UserFrosting\Sprinkle\Core\Exceptions\MigrationRollbackException; @@ -24,21 +22,14 @@ class Migrator { /** - * @var string|null The connection name (default: null) - */ - protected ?string $connection = null; - - /** - * Constructor. - * - * @param MigrationRepositoryInterface $repository The migration repository - * @param MigrationLocatorInterface $locator The Migration locator - * @param Capsule $db The database + * @param MigrationRepositoryInterface $repository The migration repository + * @param MigrationLocatorInterface $locator The Migration locator + * @param Connection $dbConnection The database connection */ public function __construct( protected MigrationRepositoryInterface $repository, protected MigrationLocatorInterface $locator, - protected Capsule $db, + protected Connection $dbConnection, ) { } @@ -336,7 +327,7 @@ public function migrate(bool $step = false): array }; // TODO : See if Transaction still needs to be used - if ($this->getSchemaGrammar()->supportsSchemaTransactions()) { + if ($this->transactionsSupported()) { $this->getConnection()->transaction($callback); } else { $callback(); @@ -544,7 +535,7 @@ protected function runDownMigrations(array $migrations): void }; // TODO : See if Transaction still needs to be used - if ($this->getSchemaGrammar()->supportsSchemaTransactions()) { + if ($this->transactionsSupported()) { $this->getConnection()->transaction($callback); } else { $callback(); @@ -644,40 +635,20 @@ public function setLocator(MigrationLocatorInterface $locator): static * * @return Connection */ - public function getConnection(): Connection - { - return $this->db->getConnection($this->getConnectionName()); - } - - /** - * Set database connection name. - * - * @param string|null $connection - */ - public function setConnectionName(?string $connection): static - { - $this->connection = $connection; - - return $this; - } - - /** - * Resolve the database connection instance. - * - * @return string|null The connection name (default: null, aka the default connection) - */ - public function getConnectionName(): ?string + protected function getConnection(): Connection { - return $this->connection; + return $this->dbConnection; } /** - * Get instance of Schema Grammar. + * Return if database transaction are supported by current db connection. * - * @return Grammar + * @return bool */ - protected function getSchemaGrammar(): Grammar + protected function transactionsSupported(): bool { - return $this->getConnection()->getSchemaGrammar(); + return $this->getConnection() + ->getSchemaGrammar() + ->supportsSchemaTransactions(); } } diff --git a/app/src/ServicesProvider/DatabaseService.php b/app/src/ServicesProvider/DatabaseService.php index 8c0308a4..3770c629 100644 --- a/app/src/ServicesProvider/DatabaseService.php +++ b/app/src/ServicesProvider/DatabaseService.php @@ -33,7 +33,7 @@ class DatabaseService implements ServicesProviderInterface public function register(): array { return [ - Capsule::class => function (Config $config, LogExecutedQuery $logger) { + Capsule::class => function (Config $config, LogExecutedQuery $logger) { $capsule = new Capsule(); // Add each defined connection in the config @@ -63,11 +63,11 @@ public function register(): array return $capsule; }, - Builder::class => function (Connection $connection) { + Builder::class => function (Connection $connection) { return $connection->getSchemaBuilder(); }, - Connection::class => function (Capsule $db) { + Connection::class => function (Capsule $db) { $connection = $db->getDatabaseManager()->getDefaultConnection(); return $db->getConnection($connection); diff --git a/app/tests/Integration/Bakery/DebugCommandTest.php b/app/tests/Integration/Bakery/DebugCommandTest.php index eca8ac0c..3f0cd8ba 100644 --- a/app/tests/Integration/Bakery/DebugCommandTest.php +++ b/app/tests/Integration/Bakery/DebugCommandTest.php @@ -12,7 +12,7 @@ namespace UserFrosting\Sprinkle\Core\Tests\Integration\Bakery; -use Illuminate\Database\Capsule\Manager as Capsule; +use Illuminate\Database\Connection; use Mockery; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PDOException; @@ -43,10 +43,10 @@ public function testCommand(): void public function testCommandForFailDatabase(): void { // Setup mocks - $class = Mockery::mock(Capsule::class) - ->shouldReceive('getDatabaseManager')->andThrow(PDOException::class) + $class = Mockery::mock(Connection::class) + ->shouldReceive('getPdo')->andThrow(PDOException::class) ->getMock(); - $this->ci->set(Capsule::class, $class); + $this->ci->set(Connection::class, $class); $result = $this->getCommandTester(); diff --git a/app/tests/Integration/Database/Migrator/MigratorTest.php b/app/tests/Integration/Database/Migrator/MigratorTest.php index 60ef30ba..345fd1e1 100644 --- a/app/tests/Integration/Database/Migrator/MigratorTest.php +++ b/app/tests/Integration/Database/Migrator/MigratorTest.php @@ -13,6 +13,7 @@ namespace UserFrosting\Sprinkle\Core\Tests\Integration\Database\Migrator; use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Schema\Builder; use UserFrosting\Sprinkle\Core\Core; use UserFrosting\Sprinkle\Core\Database\Migration; use UserFrosting\Sprinkle\Core\Database\Migrator\MigrationLocatorInterface; @@ -45,7 +46,7 @@ public function testPretendToMigrate(): void // Initial state, table doesn't exist. // N.B.: Requires to get schema from connection, as otherwise it might // not work (different :memory: instance) - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertFalse($schema->hasTable('test')); // Pretend to migrate @@ -67,7 +68,7 @@ public function testMigrate(): void $migrator = $this->ci->get(Migrator::class); // Initial state, table doesn't exist. - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertFalse($schema->hasTable('test')); // Migrate @@ -93,7 +94,7 @@ public function testPretendToRollback(): void // Initial state, table exist. $migrator->migrate(); - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertTrue($schema->hasTable('test')); // Pretend to rollback @@ -116,7 +117,7 @@ public function testRollback(): void // Initial state, table exist. $migrator->migrate(); - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertTrue($schema->hasTable('test')); // Rollback @@ -148,7 +149,7 @@ public function testReset(): void // Install migration $result = $migrator->migrate(); $this->assertSame([StubMigrationA::class], $result); - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertTrue($schema->hasTable('test')); // Test pretend to reset @@ -160,7 +161,7 @@ public function testReset(): void // Test reset $result = $migrator->reset(); $this->assertSame([StubMigrationA::class], $result); - $schema = $migrator->getConnection()->getSchemaBuilder(); + $schema = $this->ci->get(Builder::class); $this->assertFalse($schema->hasTable('test')); } diff --git a/app/tests/Unit/Database/Migrator/MigratorDependencyTest.php b/app/tests/Unit/Database/Migrator/MigratorDependencyTest.php index aaf1840c..3d6c25c2 100644 --- a/app/tests/Unit/Database/Migrator/MigratorDependencyTest.php +++ b/app/tests/Unit/Database/Migrator/MigratorDependencyTest.php @@ -12,7 +12,6 @@ namespace UserFrosting\Sprinkle\Core\Tests\Unit\Database\Migrator; -use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Connection; use Mockery; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; @@ -59,11 +58,7 @@ public function testConstruct(): Migrator ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); $this->assertInstanceOf(Migrator::class, $analyser); @@ -161,11 +156,7 @@ public function testGetPendingThirdStageDependency(): void ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); $this->assertSame([ StubAnalyserMigrationC::class, // C is before B because B depend on C @@ -193,11 +184,7 @@ public function testGetPendingWithNonAvailable(): void ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); $this->expectException(MigrationDependencyNotMetException::class); $this->expectExceptionMessage(StubAnalyserMigrationG::class . ' depends on ' . StubAnalyserMigrationF::class . ", but it's not available."); diff --git a/app/tests/Unit/Database/Migrator/MigratorRollbackTest.php b/app/tests/Unit/Database/Migrator/MigratorRollbackTest.php index acb0e025..e1f08f82 100644 --- a/app/tests/Unit/Database/Migrator/MigratorRollbackTest.php +++ b/app/tests/Unit/Database/Migrator/MigratorRollbackTest.php @@ -12,7 +12,6 @@ namespace UserFrosting\Sprinkle\Core\Tests\Unit\Database\Migrator; -use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Connection; use Mockery; use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; @@ -50,11 +49,7 @@ public function testGetMigrationsForRollback(): void ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); $result = $analyser->getMigrationsForRollback(1); $this->assertSame([StubAnalyserRollbackMigrationD::class], $result); @@ -79,11 +74,7 @@ public function testGetMigrationsForReset(): void ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); $result = $analyser->getMigrationsForReset(); $this->assertSame([StubAnalyserRollbackMigrationD::class], $result); @@ -117,11 +108,7 @@ public function testValidateRollbackMigration(): void ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Run command $this->assertNull($analyser->validateRollbackMigration(StubAnalyserRollbackMigrationD::class)); @@ -140,10 +127,7 @@ public function testValidateRollbackMigrationForNotInstalledException(): void ->getMock(); $available = Mockery::mock(MigrationLocatorInterface::class); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Start by testing false $this->assertFalse($analyser->canRollbackMigration(StubAnalyserRollbackMigrationD::class)); @@ -179,10 +163,7 @@ public function testValidateRollbackMigrationForStaleException(): void ]) ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Start by testing false $this->assertFalse($analyser->canRollbackMigration(StubAnalyserRollbackMigrationD::class)); @@ -220,10 +201,7 @@ public function testValidateRollbackMigrationForDependenciesNotMet(): void ->shouldReceive('has')->with(StubAnalyserRollbackMigrationC::class)->twice()->andReturn(true) ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Run command $this->assertFalse($analyser->canRollbackMigration(StubAnalyserRollbackMigrationC::class)); @@ -261,10 +239,7 @@ public function testValidateRollbackMigrationForDependenciesDoesntExist(): void ->shouldReceive('has')->with(StubAnalyserRollbackMigrationC::class)->twice()->andReturn(false) ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Run command $this->assertFalse($analyser->canRollbackMigration(StubAnalyserRollbackMigrationA::class)); @@ -299,10 +274,7 @@ public function testValidateRollbackMigrationForDependenciesDoesntExistWithDirec ->shouldReceive('has')->with(StubAnalyserRollbackMigrationC::class)->twice()->andReturn(false) ->getMock(); $connection = Mockery::mock(Connection::class); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); - $analyser = new Migrator($installed, $available, $database); + $analyser = new Migrator($installed, $available, $connection); // Run command $this->assertFalse($analyser->canRollbackMigration(StubAnalyserRollbackMigrationB::class)); diff --git a/app/tests/Unit/Database/Migrator/MigratorTest.php b/app/tests/Unit/Database/Migrator/MigratorTest.php index 6090e14b..0b7f76ba 100644 --- a/app/tests/Unit/Database/Migrator/MigratorTest.php +++ b/app/tests/Unit/Database/Migrator/MigratorTest.php @@ -12,7 +12,6 @@ namespace UserFrosting\Sprinkle\Core\Tests\Unit\Database\Migrator; -use Illuminate\Database\Capsule\Manager as Capsule; use Illuminate\Database\Connection; use Illuminate\Database\Schema\Grammars\Grammar; use Mockery; @@ -35,10 +34,9 @@ class MigratorTest extends TestCase use MockeryPHPUnitIntegration; // Shared mock objects - protected MigrationRepositoryInterface | \Mockery\MockInterface $repository; - protected MigrationLocatorInterface | \Mockery\MockInterface $locator; - protected Connection | \Mockery\MockInterface $connection; - protected Capsule | \Mockery\MockInterface $database; + protected MigrationRepositoryInterface $repository; + protected MigrationLocatorInterface $locator; + protected Connection $connection; /** * Setup base mock and migrator instance. @@ -50,21 +48,20 @@ public function setUp(): void // Create mock objects $this->connection = Mockery::mock(Connection::class); - $this->database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($this->connection) - ->getMock(); $this->repository = Mockery::mock(MigrationRepositoryInterface::class); $this->locator = Mockery::mock(MigrationLocatorInterface::class); } protected function getMigrator(): Migrator { - return new Migrator($this->repository, $this->locator, $this->database); + return new Migrator($this->repository, $this->locator, $this->connection); } public function testConstructor(): Migrator { $migrator = $this->getMigrator(); + + // @phpstan-ignore-next-line $this->assertInstanceOf(Migrator::class, $migrator); return $migrator; @@ -78,9 +75,11 @@ public function testConstructor(): Migrator public function testRepositoryMethods(Migrator $migrator): void { // Assert get repo from the main one + // @phpstan-ignore-next-line $this->assertInstanceOf(MigrationRepositoryInterface::class, $migrator->getRepository()); // Get mock + /** @var MigrationRepositoryInterface */ $repository = Mockery::mock(MigrationRepositoryInterface::class) ->shouldReceive('exists')->twice()->andReturn(true, false) ->getMock(); @@ -103,6 +102,7 @@ public function testRepositoryMethods(Migrator $migrator): void public function testLocatorMethods(Migrator $migrator): void { // Assert get locator from the main one + // @phpstan-ignore-next-line $this->assertInstanceOf(MigrationLocatorInterface::class, $migrator->getLocator()); // Get new mock @@ -114,22 +114,6 @@ public function testLocatorMethods(Migrator $migrator): void $this->assertSame($locator, $migrator->getLocator()); } - /** - * @depends testConstructor - * - * @param Migrator $migrator - */ - public function testConnectionMethods(Migrator $migrator): void - { - // Assert get Connection from the main one - $this->assertInstanceOf(Connection::class, $migrator->getConnection()); // @phpstan-ignore-line - - // Set new mock and test change - $this->assertNull($migrator->getConnectionName()); - $migrator->setConnectionName('foo'); - $this->assertSame('foo', $migrator->getConnectionName()); - } - /** * @depends testConstructor * @@ -165,12 +149,9 @@ public function testMigrate(Migrator $migrator): void $connection = Mockery::mock(Connection::class) ->shouldReceive('getSchemaGrammar')->times(2)->andReturn($grammar) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getPending')->once()->andReturn([$migration1::class, $migration2::class]); // Migrate (Step = false) @@ -215,12 +196,9 @@ public function testMigrateWithStepsAndTransaction(Migrator $migrator): void ->shouldReceive('getSchemaGrammar')->times(2)->andReturn($grammar) ->shouldReceive('transaction')->times(2) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getPending')->once()->andReturn([$migration1::class, $migration2::class]); // Migrate (Step = true) @@ -267,12 +245,9 @@ public function testPretendToMigrate(): void $connection = Mockery::mock(Connection::class) ->shouldReceive('pretend')->once()->andReturn($queries) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getPending')->once()->andReturn([$migration::class]); // Pretend to migrate @@ -336,12 +311,9 @@ public function testRollback(Migrator $migrator): void $connection = Mockery::mock(Connection::class) ->shouldReceive('getSchemaGrammar')->times(2)->andReturn($grammar) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getMigrationsForRollback')->with(1)->once()->andReturn([$migration1::class, $migration2::class]); // Rollback (steps = 1; default) @@ -385,12 +357,9 @@ public function testRollbackWithStepsAndTransaction(Migrator $migrator): void ->shouldReceive('getSchemaGrammar')->times(2)->andReturn($grammar) ->shouldReceive('transaction')->times(2) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getMigrationsForRollback')->with(2)->once()->andReturn([$migration1::class, $migration2::class]); // Migrate (Step = true) @@ -437,12 +406,9 @@ public function testPretendToRollback(): void $connection = Mockery::mock(Connection::class) ->shouldReceive('pretend')->once()->andReturn($queries) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getMigrationsForRollback')->once()->andReturn([$migration::class]); // Pretend to migrate @@ -506,12 +472,9 @@ public function testReset(Migrator $migrator): void $connection = Mockery::mock(Connection::class) ->shouldReceive('getSchemaGrammar')->times(2)->andReturn($grammar) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getMigrationsForReset')->once()->andReturn([$migration1::class, $migration2::class]); // Reset @@ -558,12 +521,9 @@ public function testPretendToReset(): void $connection = Mockery::mock(Connection::class) ->shouldReceive('pretend')->once()->andReturn($queries) ->getMock(); - $database = Mockery::mock(Capsule::class) - ->shouldReceive('getConnection')->with(null)->andReturn($connection) - ->getMock(); // Create partial mock of migrator, so we can spoof "getPending" - $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $database])->makePartial(); + $migrator = Mockery::mock(Migrator::class, [$this->repository, $locator, $connection])->makePartial(); $migrator->shouldReceive('getMigrationsForReset')->once()->andReturn([$migration::class]); // Pretend to migrate