Skip to content

Commit 54ca29e

Browse files
authored
Add test for uuid (#248)
* Add test for uuid * styleci fix
1 parent 5791f72 commit 54ca29e

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

tests/CommandTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,27 @@ public function testUpsert(array $firstData, array $secondData): void
293293
{
294294
parent::testUpsert($firstData, $secondData);
295295
}
296+
297+
public function testinsertWithReturningPksUuid(): void
298+
{
299+
$db = $this->getConnection(true);
300+
$insertedUuid = '875343b3-6bd0-4bec-81bb-aa68bb52d945';
301+
302+
$command = $db->createCommand();
303+
$result = $command->insertWithReturningPks(
304+
'{{%table_uuid}}',
305+
[
306+
'col' => 'test',
307+
],
308+
);
309+
310+
$this->assertIsString($result['uuid']);
311+
312+
// for example ['uuid' => 738146be-87b1-49f2-9913-36142fb6fcbe]
313+
$this->assertStringMatchesFormat('%s-%s-%s-%s-%s', $result['uuid']);
314+
315+
$this->assertEquals(36, strlen($result['uuid']));
316+
317+
$db->close();
318+
}
296319
}

tests/Provider/SchemaProvider.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,37 @@ public static function columns(): array
338338
],
339339
'animal',
340340
],
341+
[
342+
[
343+
'uuid' => [
344+
'type' => 'string',
345+
'dbType' => 'uuid',
346+
'phpType' => 'string',
347+
'primaryKey' => true,
348+
'allowNull' => false,
349+
'autoIncrement' => false,
350+
'enumValues' => null,
351+
'size' => null,
352+
'precision' => null,
353+
'scale' => null,
354+
'defaultValue' => null,
355+
],
356+
'col' => [
357+
'type' => 'string',
358+
'dbType' => 'varchar',
359+
'phpType' => 'string',
360+
'primaryKey' => false,
361+
'allowNull' => true,
362+
'autoIncrement' => false,
363+
'enumValues' => null,
364+
'size' => 16,
365+
'precision' => null,
366+
'scale' => null,
367+
'defaultValue' => null,
368+
],
369+
],
370+
'table_uuid',
371+
],
341372
];
342373
}
343374

tests/Support/Fixture/pgsql.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ DROP TABLE IF EXISTS "T_constraints_1";
3434
DROP TABLE IF EXISTS "T_upsert";
3535
DROP TABLE IF EXISTS "T_upsert_1";
3636
DROP TABLE IF EXISTS "table_with_array_col";
37+
DROP TABLE IF EXISTS "table_uuid";
3738

3839
DROP SCHEMA IF EXISTS "schema1" CASCADE;
3940
DROP SCHEMA IF EXISTS "schema2" CASCADE;
4041

4142
CREATE SCHEMA "schema1";
4243
CREATE SCHEMA "schema2";
4344

45+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
46+
4447
CREATE TABLE "constraints"
4548
(
4649
id integer not null,
@@ -431,3 +434,8 @@ CREATE TABLE "table_with_array_col" (
431434
"id" SERIAL NOT NULL PRIMARY KEY,
432435
"array_col" integer ARRAY[4]
433436
);
437+
438+
CREATE TABLE "table_uuid" (
439+
"uuid" uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
440+
"col" varchar(16)
441+
);

0 commit comments

Comments
 (0)