|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace SingleStore\Laravel\Tests\Hybrid; |
| 4 | + |
| 5 | +use Illuminate\Support\Facades\DB; |
| 6 | +use Illuminate\Support\Facades\Schema; |
| 7 | +use SingleStore\Laravel\Schema\Blueprint; |
| 8 | +use SingleStore\Laravel\Tests\BaseTest; |
| 9 | + |
| 10 | +class RenameTableTest extends BaseTest |
| 11 | +{ |
| 12 | + use HybridTestHelpers; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + parent::setUp(); |
| 17 | + |
| 18 | + if ($this->runHybridIntegrations()) { |
| 19 | + $this->createTable(function (Blueprint $table) { |
| 20 | + $table->id(); |
| 21 | + }); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + protected function tearDown(): void |
| 26 | + { |
| 27 | + if ($this->runHybridIntegrations()) { |
| 28 | + Schema::dropIfExists('test_renamed'); |
| 29 | + } |
| 30 | + |
| 31 | + parent::tearDown(); |
| 32 | + } |
| 33 | + |
| 34 | + /** @test */ |
| 35 | + public function rename_table() |
| 36 | + { |
| 37 | + if ($this->runHybridIntegrations()) { |
| 38 | + $cached = $this->mockDatabaseConnection; |
| 39 | + |
| 40 | + $this->mockDatabaseConnection = false; |
| 41 | + |
| 42 | + $this->assertFalse(Schema::hasTable('test_renamed')); |
| 43 | + Schema::rename('test', 'test_renamed'); |
| 44 | + |
| 45 | + $this->assertTrue(Schema::hasTable('test_renamed')); |
| 46 | + |
| 47 | + $this->mockDatabaseConnection = $cached; |
| 48 | + } |
| 49 | + |
| 50 | + $blueprint = new Blueprint('test'); |
| 51 | + $blueprint->rename('test_renamed'); |
| 52 | + |
| 53 | + $statements = $blueprint->toSql($this->getConnection(), $this->getGrammar()); |
| 54 | + |
| 55 | + $this->assertCount(1, $statements); |
| 56 | + $this->assertEquals('alter table `test` rename to `test_renamed`', $statements[0]); |
| 57 | + |
| 58 | + } |
| 59 | +} |
0 commit comments