|
13 | 13 |
|
14 | 14 | namespace Phalcon\Migrations\Tests\Postgresql; |
15 | 15 |
|
| 16 | +use Exception; |
16 | 17 | use Phalcon\Db\Column; |
| 18 | +use Phalcon\Db\Index; |
| 19 | +use Phalcon\Migrations\Db\Adapter\Pdo\PdoPostgresql; |
17 | 20 | use Phalcon\Migrations\Migrations; |
18 | 21 | use PostgresqlTester; |
19 | 22 |
|
20 | 23 | final class IssuesCest |
21 | 24 | { |
22 | 25 | public function issue1(PostgresqlTester $I): void |
23 | 26 | { |
| 27 | + $I->wantToTest('Issue #1 - Primary key was created'); |
| 28 | + |
24 | 29 | $tableName = 'table_primary_test'; |
25 | 30 | $migrationsDir = codecept_output_dir(__FUNCTION__); |
26 | 31 |
|
@@ -56,4 +61,123 @@ public function issue1(PostgresqlTester $I): void |
56 | 61 |
|
57 | 62 | $I->assertSame(1, count($indexes)); |
58 | 63 | } |
| 64 | + |
| 65 | + /** |
| 66 | + * @throws Exception |
| 67 | + */ |
| 68 | + public function testIssue111Fail(PostgresqlTester $I): void |
| 69 | + { |
| 70 | + $I->wantToTest('Issue #111 - Unrecognized PostgreSQL data type [FAIL]'); |
| 71 | + |
| 72 | + $tableName = 'pg_phalcon_double'; |
| 73 | + $migrationsDir = codecept_output_dir(__FUNCTION__); |
| 74 | + |
| 75 | + $I->seeExceptionThrown( |
| 76 | + Phalcon\Db\Exception::class, |
| 77 | + function () use ($I, $tableName) { |
| 78 | + $I->getPhalconDb()->createTable($tableName, $I->getDefaultSchema(), [ |
| 79 | + 'columns' => [ |
| 80 | + new Column('point_double_column', [ |
| 81 | + 'type' => Column::TYPE_DOUBLE, |
| 82 | + 'default' => 0, |
| 83 | + 'notNull' => false, |
| 84 | + 'comment' => "Double typed column", |
| 85 | + ]), |
| 86 | + ], |
| 87 | + ]); |
| 88 | + } |
| 89 | + ); |
| 90 | + |
| 91 | + ob_start(); |
| 92 | + Migrations::generate([ |
| 93 | + 'migrationsDir' => [ |
| 94 | + $migrationsDir, |
| 95 | + ], |
| 96 | + 'config' => $I->getMigrationsConfig(), |
| 97 | + 'tableName' => '@', |
| 98 | + ]); |
| 99 | + $I->getPhalconDb()->dropTable($tableName); |
| 100 | + Migrations::run([ |
| 101 | + 'migrationsDir' => $migrationsDir, |
| 102 | + 'config' => $I->getMigrationsConfig(), |
| 103 | + 'migrationsInDb' => true, |
| 104 | + ]); |
| 105 | + ob_clean(); |
| 106 | + |
| 107 | + $indexes = $I->getPhalconDb()->describeIndexes(Migrations::MIGRATION_LOG_TABLE); |
| 108 | + |
| 109 | + $I->assertFalse($I->getPhalconDb()->tableExists($tableName, $I->getDefaultSchema())); |
| 110 | + $I->assertTrue($I->getPhalconDb()->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); |
| 111 | + $I->assertSame(1, count($indexes)); |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * @throws Exception |
| 116 | + */ |
| 117 | + public function testIssue111Fixed(PostgresqlTester $I): void |
| 118 | + { |
| 119 | + $I->wantToTest('Issue #111 - Unrecognized PostgreSQL data type [FIXED]'); |
| 120 | + |
| 121 | + $tableName = 'pg_phalcon_double'; |
| 122 | + $migrationsDir = codecept_output_dir(__FUNCTION__); |
| 123 | + $I->getPhalconDb()->createTable($tableName, $I->getDefaultSchema(), [ |
| 124 | + 'columns' => [ |
| 125 | + new Column('point_double_column', [ |
| 126 | + 'type' => Column::TYPE_FLOAT, |
| 127 | + 'default' => 0, |
| 128 | + 'notNull' => false, |
| 129 | + 'comment' => "Double typed column", |
| 130 | + ]), |
| 131 | + ], |
| 132 | + ]); |
| 133 | + |
| 134 | + ob_start(); |
| 135 | + Migrations::generate([ |
| 136 | + 'migrationsDir' => [ |
| 137 | + $migrationsDir, |
| 138 | + ], |
| 139 | + 'config' => $I->getMigrationsConfig(), |
| 140 | + 'tableName' => '@', |
| 141 | + ]); |
| 142 | + $I->getPhalconDb()->dropTable($tableName); |
| 143 | + Migrations::run([ |
| 144 | + 'migrationsDir' => $migrationsDir, |
| 145 | + 'config' => $I->getMigrationsConfig(), |
| 146 | + 'migrationsInDb' => true, |
| 147 | + ]); |
| 148 | + ob_clean(); |
| 149 | + |
| 150 | + $indexes = $I->getPhalconDb()->describeIndexes(Migrations::MIGRATION_LOG_TABLE); |
| 151 | + |
| 152 | + $I->assertTrue($I->getPhalconDb()->tableExists($tableName, $I->getDefaultSchema())); |
| 153 | + $I->assertTrue($I->getPhalconDb()->tableExists(Migrations::MIGRATION_LOG_TABLE, $I->getDefaultSchema())); |
| 154 | + $I->assertSame(1, count($indexes)); |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * @throws Exception |
| 159 | + */ |
| 160 | + public function testIssue112(PostgresqlTester $I): void |
| 161 | + { |
| 162 | + $I->wantToTest('Issue #112 - Index should be primary key, instead of Normal Index'); |
| 163 | + |
| 164 | + $tableName = 'pg_phalcon_primary_index'; |
| 165 | + $I->getPhalconDb()->createTable($tableName, $I->getDefaultSchema(), [ |
| 166 | + 'columns' => [ |
| 167 | + new Column('id', [ |
| 168 | + 'type' => Column::TYPE_INTEGER, |
| 169 | + 'notNull' => true, |
| 170 | + 'first' => true, |
| 171 | + ]), |
| 172 | + ], |
| 173 | + 'indexes' => [ |
| 174 | + new Index('pk_id_0', ['id'], 'PRIMARY KEY'), |
| 175 | + ], |
| 176 | + ]); |
| 177 | + |
| 178 | + $indexes = $I->getPhalconDb()->describeIndexes($tableName, $I->getDefaultSchema()); |
| 179 | + $index = array_shift($indexes); |
| 180 | + |
| 181 | + $I->assertSame(PdoPostgresql::INDEX_TYPE_PRIMARY, $index->getType()); |
| 182 | + } |
59 | 183 | } |
0 commit comments