Skip to content

Commit b72e576

Browse files
committed
tests added.
1 parent 1266ae0 commit b72e576

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Service/Parser/SchemaParserInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace N3XT0R\MigrationGenerator\Service\Parser;
55

6+
use Illuminate\Database\ConnectionInterface;
7+
68

79
interface SchemaParserInterface
810
{
@@ -12,4 +14,9 @@ public function getSortedTablesFromSchema(string $schema): array;
1214

1315
public function setConnectionByName(string $connectionName = ''): void;
1416

17+
public function setConnection(?ConnectionInterface $connection): void;
18+
19+
public function getConnection(): ConnectionInterface;
20+
21+
1522
}

tests/Integration/Service/Parser/SchemaParserTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
use Illuminate\Foundation\Application;
8+
use Illuminate\Support\Facades\DB;
89
use N3XT0R\MigrationGenerator\Service\Parser\SchemaParserInterface;
910
use Tests\DbTestCase;
1011

@@ -48,7 +49,7 @@ public function testGetTablesFromSchemaWorks(): void
4849
'users',
4950
],
5051
};
51-
52+
5253

5354
self::assertSame($expectedTables, $tables);
5455
}
@@ -85,4 +86,26 @@ public function testGetSortedTablesFromSchema(): void
8586
self::assertCount(count($expectedTables), $tables);
8687
self::assertSame($expectedTables, $tables);
8788
}
89+
90+
91+
public function testSetConnectionByNameWorksWithDefaultConnection(): void
92+
{
93+
$defaultConnection = DB::connection();
94+
95+
$this->parser->setConnectionByName();
96+
$connection = $this->parser->getConnection();
97+
98+
self::assertSame($defaultConnection->getDatabaseName(), $connection->getDatabaseName());
99+
}
100+
101+
public function testSetConnectionByNameWorksWithCustomConnection(): void
102+
{
103+
$connectionName = $this->getDatabaseFromEnv();
104+
$customConnection = DB::connection($connectionName);
105+
106+
$this->parser->setConnectionByName($connectionName);
107+
$connection = $this->parser->getConnection();
108+
109+
self::assertSame($customConnection->getDatabaseName(), $connection->getDatabaseName());
110+
}
88111
}

0 commit comments

Comments
 (0)