|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Phalcon\Migrations\Tests\Mysql; |
| 6 | + |
| 7 | +use MysqlTester; |
| 8 | +use Phalcon\Db\Column; |
| 9 | +use Phalcon\Db\Exception; |
| 10 | +use Phalcon\Db\Index; |
| 11 | +use Phalcon\Migrations\Migrations; |
| 12 | + |
| 13 | +/** |
| 14 | + * @see https://github.com/phalcon/migrations/issues/94 |
| 15 | + */ |
| 16 | +final class Issue94Cest |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @param MysqlTester $I |
| 20 | + * @throws Exception |
| 21 | + */ |
| 22 | + public function testIssue94(MysqlTester $I): void |
| 23 | + { |
| 24 | + $I->wantToTest('Issue #94 - Engine "MEMORY"'); |
| 25 | + |
| 26 | + ob_start(); |
| 27 | + Migrations::run([ |
| 28 | + 'migrationsDir' => codecept_data_dir('issues/94'), |
| 29 | + 'config' => $I->getMigrationsConfig(), |
| 30 | + 'migrationsInDb' => true, |
| 31 | + ]); |
| 32 | + ob_clean(); |
| 33 | + |
| 34 | + $options = $I->getPhalconDb()->tableOptions('memory_table'); |
| 35 | + |
| 36 | + $I->assertSame('MEMORY', $options['engine']); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @param MysqlTester $I |
| 41 | + * @throws Exception |
| 42 | + */ |
| 43 | + public function testGenerateIssue94(MysqlTester $I): void |
| 44 | + { |
| 45 | + $I->wantToTest('Issue #94 - Correct options generation case (uppercase)'); |
| 46 | + |
| 47 | + $engine = 'MyISAM'; |
| 48 | + $tableName = 'options_uppercase'; |
| 49 | + $migrationsDir = codecept_output_dir(__FUNCTION__); |
| 50 | + |
| 51 | + $I->getPhalconDb()->createTable($tableName, '', [ |
| 52 | + 'columns' => [ |
| 53 | + new Column('id', [ |
| 54 | + 'type' => Column::TYPE_INTEGER, |
| 55 | + 'size' => 20, |
| 56 | + 'notNull' => true, |
| 57 | + 'autoIncrement' => true, |
| 58 | + ]), |
| 59 | + ], |
| 60 | + 'indexes' => [ |
| 61 | + new Index('PRIMARY', ['id'], 'PRIMARY') |
| 62 | + ], |
| 63 | + 'options' => [ |
| 64 | + 'TABLE_TYPE' => 'BASE TABLE', |
| 65 | + 'ENGINE' => $engine, |
| 66 | + 'TABLE_COLLATION' => 'utf8mb4_general_ci', |
| 67 | + ], |
| 68 | + ]); |
| 69 | + |
| 70 | + /** |
| 71 | + * Generate | Drop | Run |
| 72 | + */ |
| 73 | + ob_start(); |
| 74 | + Migrations::generate([ |
| 75 | + 'migrationsDir' => $migrationsDir, |
| 76 | + 'config' => $I->getMigrationsConfig(), |
| 77 | + 'tableName' => $tableName, |
| 78 | + ]); |
| 79 | + $I->getPhalconDb()->dropTable($tableName); |
| 80 | + Migrations::run([ |
| 81 | + 'migrationsDir' => $migrationsDir, |
| 82 | + 'config' => $I->getMigrationsConfig(), |
| 83 | + 'migrationsInDb' => true, |
| 84 | + ]); |
| 85 | + ob_clean(); |
| 86 | + |
| 87 | + $I->assertSame($engine, $I->getPhalconDb()->tableOptions($tableName)['engine']); |
| 88 | + } |
| 89 | +} |
0 commit comments