Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@
<code><![CDATA[$param]]></code>
<code><![CDATA[$param]]></code>
<code><![CDATA[$param]]></code>
<code><![CDATA[$tokens['alias']]]></code>
<code><![CDATA[$tokens['columns']]]></code>
<code><![CDATA[$tokens['columns']]]></code>
<code><![CDATA[$tokens['distinct']]]></code>
Expand Down Expand Up @@ -379,6 +380,7 @@
<code><![CDATA[$identifier]]></code>
</MoreSpecificImplementedParamType>
<PossiblyUndefinedStringArrayOffset>
<code><![CDATA[$tokens['alias']]]></code>
<code><![CDATA[$tokens['columns']]]></code>
<code><![CDATA[$tokens['columns']]]></code>
<code><![CDATA[$tokens['distinct']]]></code>
Expand Down Expand Up @@ -901,19 +903,20 @@
</MixedAssignment>
<PossiblyUndefinedStringArrayOffset>
<code><![CDATA[$matches['type']]]></code>
<code><![CDATA[$schema['Comment']]]></code>
<code><![CDATA[$schema['Default']]]></code>
<code><![CDATA[$schema['Extra']]]></code>
<code><![CDATA[$schema['Field']]]></code>
<code><![CDATA[$schema['Null']]]></code>
<code><![CDATA[$schema['Type']]]></code>
<code><![CDATA[$schema['Comment']]]></code>
</PossiblyUndefinedStringArrayOffset>
<RiskyTruthyFalsyComparison>
<code><![CDATA[empty($matches['attr'])]]></code>
<code><![CDATA[empty($matches['options'])]]></code>
</RiskyTruthyFalsyComparison>
<UndefinedInterfaceMethod>
<code><![CDATA[identifier]]></code>
<code><![CDATA[identifier]]></code>
</UndefinedInterfaceMethod>
</file>
<file src="src/Driver/MySQL/Schema/MySQLForeignKey.php">
Expand Down Expand Up @@ -1303,10 +1306,10 @@
<code><![CDATA[$identifier]]></code>
<code><![CDATA[$identifier]]></code>
<code><![CDATA[$range]]></code>
<code><![CDATA[$tableName]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$value]]></code>
<code><![CDATA[$tableName]]></code>
</MixedAssignment>
<MixedOperand>
<code><![CDATA[$schema['dtd_identifier']]]></code>
Expand All @@ -1321,6 +1324,7 @@
<code><![CDATA[$schema['column_name']]]></code>
<code><![CDATA[$schema['data_type']]]></code>
<code><![CDATA[$schema['datetime_precision']]]></code>
<code><![CDATA[$schema['description']]]></code>
<code><![CDATA[$schema['dtd_identifier']]]></code>
<code><![CDATA[$schema['interval_type']]]></code>
<code><![CDATA[$schema['is_nullable']]]></code>
Expand All @@ -1330,7 +1334,6 @@
<code><![CDATA[$schema['tableOID']]]></code>
<code><![CDATA[$schema['typname']]]></code>
<code><![CDATA[$schema['typtype']]]></code>
<code><![CDATA[$schema['description']]]></code>
</PossiblyUndefinedStringArrayOffset>
<RedundantCast>
<code><![CDATA[(bool) (
Expand Down Expand Up @@ -2424,6 +2427,14 @@
<code><![CDATA[$value]]></code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Injection/SubQuery.php">
<ClassMustBeFinal>
<code><![CDATA[SubQuery]]></code>
</ClassMustBeFinal>
<MixedPropertyTypeCoercion>
<code><![CDATA[$parameters->getParameters()]]></code>
</MixedPropertyTypeCoercion>
</file>
<file src="src/Query/ActiveQuery.php">
<PossiblyNullArgument>
<code><![CDATA[$this->prefix]]></code>
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Jsoner.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function toJson(mixed $value, bool $encode = true, bool $validate

$result = (string) $value;

if ($validate && !json_validate($result)) {
if ($validate && !\json_validate($result)) {
throw new BuilderException('Invalid JSON value.');
}

Expand Down
1 change: 1 addition & 0 deletions src/Driver/MySQL/Schema/MySQLColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class MySQLColumn extends AbstractColumn

//Additional types
'json' => 'json',
'ulid' => ['type' => 'varchar', 'size' => 26],
'uuid' => ['type' => 'varchar', 'size' => 36],
];
protected array $reverseMapping = [
Expand Down
1 change: 1 addition & 0 deletions src/Driver/Postgres/Schema/PostgresColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class PostgresColumn extends AbstractColumn
//Additional types
'json' => 'json',
'jsonb' => 'jsonb',
'ulid' => ['type' => 'character varying', 'size' => 26],
'uuid' => 'uuid',
'point' => 'point',
'line' => 'line',
Expand Down
1 change: 1 addition & 0 deletions src/Driver/SQLServer/Schema/SQLServerColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class SQLServerColumn extends AbstractColumn

//Additional types
'json' => ['type' => 'varchar', 'size' => 0],
'ulid' => ['type' => 'varchar', 'size' => 26],
'uuid' => ['type' => 'varchar', 'size' => 36],
];
protected array $reverseMapping = [
Expand Down
1 change: 1 addition & 0 deletions src/Driver/SQLite/Schema/SQLiteColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class SQLiteColumn extends AbstractColumn

//Additional types
'json' => 'text',
'ulid' => ['type' => 'varchar', 'size' => 26],
'uuid' => ['type' => 'varchar', 'size' => 36],
];
protected array $reverseMapping = [
Expand Down
1 change: 1 addition & 0 deletions src/Schema/AbstractColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* @method $this|AbstractColumn tinyBinary()
* @method $this|AbstractColumn longBinary()
* @method $this|AbstractColumn json()
* @method $this|AbstractColumn ulid()
* @method $this|AbstractColumn uuid()
*/
abstract class AbstractColumn implements ColumnInterface, ElementInterface
Expand Down
1 change: 1 addition & 0 deletions src/Schema/AbstractTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @method AbstractColumn binary($column)
* @method AbstractColumn tinyBinary($column)
* @method AbstractColumn longBinary($column)
* @method AbstractColumn ulid($column)
* @method AbstractColumn uuid($column)
*/
abstract class AbstractTable implements TableInterface, ElementInterface
Expand Down
114 changes: 114 additions & 0 deletions tests/Database/Functional/Driver/Common/Schema/ConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,92 @@ public function testTime(): void
$this->assertTrue($schema->column('target')->compare($column));
}

public function testUlid(): void
{
$schema = $this->schema('table');
$this->assertFalse($schema->exists());

$column = $schema->ulid('target');

$schema->save();

$schema = $this->schema('table');
$this->assertTrue($schema->exists());
$this->assertTrue($schema->column('target')->compare($column));
$this->assertSame('string', $schema->column('target')->getType());

$this->database->table('table')->insertOne(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
);

$this->assertEquals(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
$this->database->table('table')->select()->fetchAll()[0],
);
}

public function testUlidCallingColumnMethod(): void
{
$schema = $this->schema('table');
$this->assertFalse($schema->exists());

$column = $schema->column('target')->ulid();

$schema->save();

$schema = $this->schema('table');
$this->assertTrue($schema->exists());
$this->assertTrue($schema->column('target')->compare($column));
$this->assertSame('string', $schema->column('target')->getType());

$this->database->table('table')->insertOne(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
);

$this->assertEquals(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
$this->database->table('table')->select()->fetchAll()[0],
);
}

public function testUlidPrimary(): void
{
$schema = $this->schema('table');
$this->assertFalse($schema->exists());

$column = $schema->ulid('target')->nullable(false);
$schema->setPrimaryKeys(['target']);
$schema->save();

$schema = $this->schema('table');
$this->assertTrue($schema->exists());

$this->assertTrue($schema->column('target')->compare($column));
$this->assertSame('string', $schema->column('target')->getType());
$this->assertSame(['target'], $schema->getPrimaryKeys());

$this->database->table('table')->insertOne(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
);

$this->assertEquals(
[
'target' => '0GWWXY2G84DFMRVWQNJ1SRYCMC',
],
$this->database->table('table')->select()->fetchAll()[0],
);
}

public function testUuid(): void
{
$schema = $this->schema('table');
Expand Down Expand Up @@ -388,6 +474,34 @@ public function testUuid(): void
);
}

public function testUuidCallingColumnMethod(): void
{
$schema = $this->schema('table');
$this->assertFalse($schema->exists());

$column = $schema->column('target')->uuid();

$schema->save();

$schema = $this->schema('table');
$this->assertTrue($schema->exists());
$this->assertTrue($schema->column('target')->compare($column));
$this->assertSame('string', $schema->column('target')->getType());

$this->database->table('table')->insertOne(
[
'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
],
);

$this->assertEquals(
[
'target' => 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
],
$this->database->table('table')->select()->fetchAll()[0],
);
}

public function testUuidPrimary(): void
{
$schema = $this->schema('table');
Expand Down
Loading