Skip to content

Commit c4d9ade

Browse files
committed
add unit test for unique index handling (pgsql only)
1 parent 0f9bbdb commit c4d9ade

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

tests/Propel/Tests/Generator/Platform/PgsqlPlatformMigrationTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ public function testGetModifyTableIndicesDDL($tableDiff)
155155
156156
DROP INDEX "bar_fk";
157157
158+
ALTER TABLE "foo" DROP CONSTRAINT "bax_unique";
159+
158160
CREATE INDEX "baz_fk" ON "foo" ("baz");
159161
162+
ALTER TABLE "foo" ADD CONSTRAINT "bax_bay_unique" UNIQUE ("bax","bay");
163+
160164
DROP INDEX "bar_baz_fk";
161165
162166
CREATE INDEX "bar_baz_fk" ON "foo" ("id","bar","baz");

tests/Propel/Tests/Generator/Platform/PgsqlPlatformTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,17 @@ public function testAddIndexDDL($index)
600600
$this->assertEquals($expected, $this->getPlatform()->getAddIndexDDL($index));
601601
}
602602

603+
/**
604+
* @dataProvider providerForTestGetUniqueIndexDDL
605+
*/
606+
public function testAddUniqueIndexDDL($index)
607+
{
608+
$expected = '
609+
ALTER TABLE "foo" ADD CONSTRAINT "babar" UNIQUE ("bar1");
610+
';
611+
$this->assertEquals($expected, $this->getPlatform()->getAddIndexDDL($index));
612+
}
613+
603614
/**
604615
* @dataProvider providerForTestGetIndicesDDL
605616
*/

tests/Propel/Tests/Generator/Platform/PlatformMigrationTestProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ public function providerForTestGetModifyTableIndicesDDL()
198198
<table name="foo">
199199
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
200200
<column name="bar" type="INTEGER" />
201+
<column name="bax" type="VARCHAR" size="12" required="true" />
201202
<column name="baz" type="VARCHAR" size="12" required="true" />
202203
<index name="bar_fk">
203204
<index-column name="bar"/>
@@ -206,6 +207,9 @@ public function providerForTestGetModifyTableIndicesDDL()
206207
<index-column name="bar"/>
207208
<index-column name="baz"/>
208209
</index>
210+
<unique name="bax_unique">
211+
<unique-column name="bax"/>
212+
</unique>
209213
</table>
210214
</database>
211215
EOF;
@@ -214,6 +218,8 @@ public function providerForTestGetModifyTableIndicesDDL()
214218
<table name="foo">
215219
<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
216220
<column name="bar" type="INTEGER" />
221+
<column name="bax" type="VARCHAR" size="12" required="true" />
222+
<column name="bay" type="VARCHAR" size="12" required="true" />
217223
<column name="baz" type="VARCHAR" size="12" required="true" />
218224
<index name="bar_baz_fk">
219225
<index-column name="id"/>
@@ -223,6 +229,10 @@ public function providerForTestGetModifyTableIndicesDDL()
223229
<index name="baz_fk">
224230
<index-column name="baz"/>
225231
</index>
232+
<unique name="bax_bay_unique">
233+
<unique-column name="bax"/>
234+
<unique-column name="bay"/>
235+
</unique>
226236
</table>
227237
</database>
228238
EOF;

tests/Propel/Tests/Generator/Platform/PlatformTestProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ public function providerForTestGetIndexDDL()
247247
];
248248
}
249249

250+
public function providerForTestGetUniqueIndexDDL()
251+
{
252+
$table = new Table('foo');
253+
$table->setIdentifierQuoting(true);
254+
$column1 = new Column('bar1');
255+
$column1->getDomain()->copy(new Domain('FOOTYPE'));
256+
$table->addColumn($column1);
257+
$index = new Unique('babar');
258+
$index->addColumn($column1);
259+
$table->addIndex($index);
260+
261+
return [
262+
[$index]
263+
];
264+
}
265+
250266
public function providerForTestPrimaryKeyDDL()
251267
{
252268
$table = new Table('foo');

0 commit comments

Comments
 (0)