|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * This file is part of Hyperf. |
| 6 | + * |
| 7 | + * @link https://www.hyperf.io |
| 8 | + * @document https://hyperf.wiki |
| 9 | + * @contact group@hyperf.io |
| 10 | + * @license https://github.com/hyperf/hyperf/blob/master/LICENSE |
| 11 | + */ |
| 12 | + |
| 13 | +namespace HyperfTest\Database\PgSQL\Cases; |
| 14 | + |
| 15 | +use Hyperf\Database\Schema\Blueprint; |
| 16 | +use Hyperf\Database\Schema\Schema; |
| 17 | +use Hyperf\DbConnection\Db; |
| 18 | +use HyperfTest\Database\PgSQL\Stubs\ContainerStub; |
| 19 | +use PHPUnit\Framework\Attributes\RequiresPhpExtension; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | + |
| 22 | +/** |
| 23 | + * @internal |
| 24 | + * @coversNothing |
| 25 | + */ |
| 26 | +#[RequiresPhpExtension('swoole', '< 6.0')] |
| 27 | +class SchemaBuilderTest extends TestCase |
| 28 | +{ |
| 29 | + protected function setUp(): void |
| 30 | + { |
| 31 | + $container = ContainerStub::getContainer(); |
| 32 | + $container->allows('get')->with(Db::class)->andReturns(new Db($container)); |
| 33 | + } |
| 34 | + |
| 35 | + protected function tearDown(): void |
| 36 | + { |
| 37 | + Schema::drop('foo'); |
| 38 | + Schema::drop('bar'); |
| 39 | + Schema::drop('baz'); |
| 40 | + } |
| 41 | + |
| 42 | + public function testGetTables(): void |
| 43 | + { |
| 44 | + Schema::create('foo', static function (Blueprint $table) { |
| 45 | + $table->comment('This is a comment'); |
| 46 | + $table->id(); |
| 47 | + }); |
| 48 | + |
| 49 | + Schema::create('bar', static function (Blueprint $table) { |
| 50 | + $table->id('name'); |
| 51 | + }); |
| 52 | + |
| 53 | + Schema::create('baz', static function (Blueprint $table) { |
| 54 | + $table->id('votes'); |
| 55 | + }); |
| 56 | + |
| 57 | + $tables = Schema::getTables(); |
| 58 | + $this->assertEmpty(array_diff(['foo', 'bar', 'baz'], array_column($tables, 'name'))); |
| 59 | + $this->assertNotEmpty(array_filter($tables, static function ($table) { |
| 60 | + return $table['name'] === 'foo'; |
| 61 | + })); |
| 62 | + } |
| 63 | +} |
0 commit comments