-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added method
Hyperf\Database\Schema::getTables()
.
- Loading branch information
Showing
4 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of Hyperf. | ||
* | ||
* @link https://www.hyperf.io | ||
* @document https://hyperf.wiki | ||
* @contact [email protected] | ||
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE | ||
*/ | ||
|
||
namespace HyperfTest\Database\PgSQL\Cases; | ||
|
||
use Hyperf\Database\Schema\Blueprint; | ||
use Hyperf\Database\Schema\Schema; | ||
use Hyperf\DbConnection\Db; | ||
use HyperfTest\Database\PgSQL\Stubs\ContainerStub; | ||
use PHPUnit\Framework\Attributes\RequiresPhpExtension; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @internal | ||
* @coversNothing | ||
*/ | ||
#[RequiresPhpExtension('swoole', '< 6.0')] | ||
class SchemaBuilderTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$container = ContainerStub::getContainer(); | ||
$container->allows('get')->with(Db::class)->andReturns(new Db($container)); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
Schema::drop('foo'); | ||
Schema::drop('bar'); | ||
Schema::drop('baz'); | ||
} | ||
|
||
public function testGetTables(): void | ||
{ | ||
Schema::create('foo', static function (Blueprint $table) { | ||
$table->comment('This is a comment'); | ||
$table->id(); | ||
}); | ||
|
||
Schema::create('bar', static function (Blueprint $table) { | ||
$table->id('name'); | ||
}); | ||
|
||
Schema::create('baz', static function (Blueprint $table) { | ||
$table->id('votes'); | ||
}); | ||
|
||
$tables = Schema::getTables(); | ||
$this->assertEmpty(array_diff(['foo', 'bar', 'baz'], array_column($tables, 'name'))); | ||
$this->assertNotEmpty(array_filter($tables, static function ($table) { | ||
return $table['name'] === 'foo'; | ||
})); | ||
} | ||
} |