Created
September 6, 2017 05:04
Revisions
-
sters created this gist
Sep 6, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,55 @@ <?php namespace Tests; use Tests\TestCase; class MigrationsTest extends TestCase { /** * Check table columns. MySQL only. * * @param string $tableName * @param array $columnInfoList */ private function __checkColumns($tableName, $columnInfoList) { $descResult = \DB::select('desc ' . $tableName . ';'); foreach ($columnInfoList as $field => $type) { $success = false; foreach ($descResult as $columnInfo) { if ($field !== $columnInfo->Field) { continue; } $message = "[{$tableName}] {$field} / {$type} - {$columnInfo->Field} / {$columnInfo->Type}"; $this->assertEquals($field, $columnInfo->Field, $message); $this->assertContains(str_replace(' ', '', $type), str_replace(' ', '', $columnInfo->Type), $message); $success = true; break; } if ($success) { continue; } $this->fail("[{$tableName}] {$field} / {$type} column not found"); } if (count($columnInfoList) != count($descResult)) { fputs(STDERR, "[MIGRATION WARNING][{$tableName}] Invalid column count. " . count($columnInfoList) . ' / ' . count($descResult) . "\n"); } } public function testAccountTable() { $this->__checkColumns('account', [ 'email' => 'varchar(191)', 'token' => 'varchar(191)', 'created_at' => 'timestamp', 'updated_at' => 'timestamp', ]); } }