Skip to content

Commit

Permalink
Respect model table and connection in database assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
devfrey committed Aug 26, 2024
1 parent d16ce25 commit 08c730b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ protected function getConnection($connection = null, $table = null)
*/
protected function getTable($table)
{
if ($table instanceof Model) {
return $table->getTable();
}

return $this->newModelFor($table)?->getTable() ?: $table;
}

Expand All @@ -283,6 +287,10 @@ protected function getTable($table)
*/
protected function getTableConnection($table)
{
if ($table instanceof Model) {
return $table->getConnectionName();
}

return $this->newModelFor($table)?->getConnectionName();
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Foundation/FoundationInteractsWithDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ public function testGetTableNameFromModel()
$this->assertEquals($this->table, $this->getTable(ProductStub::class));
$this->assertEquals($this->table, $this->getTable(new ProductStub));
$this->assertEquals($this->table, $this->getTable($this->table));
$this->assertEquals('all_products', $this->getTable((new ProductStub)->setTable('all_products')));
}

public function testGetTableConnectionNameFromModel()
{
$this->assertSame(null, $this->getTableConnection(ProductStub::class));
$this->assertSame(null, $this->getTableConnection(new ProductStub));
$this->assertSame('mysql', $this->getTableConnection((new ProductStub)->setConnection('mysql')));
}

public function testGetTableCustomizedDeletedAtColumnName()
Expand Down

0 comments on commit 08c730b

Please sign in to comment.