File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
tests/Integration/Service/Parser Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 33
44namespace N3XT0R \MigrationGenerator \Service \Parser ;
55
6+ use Illuminate \Database \ConnectionInterface ;
7+
68
79interface 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}
Original file line number Diff line number Diff line change 55
66
77use Illuminate \Foundation \Application ;
8+ use Illuminate \Support \Facades \DB ;
89use N3XT0R \MigrationGenerator \Service \Parser \SchemaParserInterface ;
910use 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}
You can’t perform that action at this time.
0 commit comments