Skip to content
Merged
2 changes: 2 additions & 0 deletions docs/AVAILABLE-FUNCTIONS-AND-OPERATORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ Complete documentation for PostgreSQL ltree (label tree) operations and hierarch
- `CRC32` - CRC-32 checksum computation
- `CRC32C` - CRC-32C checksum computation
- `REVERSE_BYTES` - Reverse byte order for bytea values
- `UUID_EXTRACT_TIMESTAMP` - Extract timestamp from UUID v1 or v7
- `UUID_EXTRACT_VERSION` - Extract version number from UUID
- `UUIDV4` - Explicit UUID version 4 generation
- `UUIDV7` - Generate timestamp-ordered UUIDs (version 7) for better database performance

Expand Down
4 changes: 4 additions & 0 deletions docs/MATHEMATICAL-FUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ This document covers PostgreSQL mathematical, utility, and miscellaneous functio
| to_char | TO_CHAR | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToChar` |
| to_number | TO_NUMBER | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ToNumber` |

**Note**: `TO_NUMBER` supports Roman numeral conversion via the `RN` pattern (PostgreSQL 18+).

## Utility and Miscellaneous Functions

| PostgreSQL functions | Register for DQL as | Implemented by |
Expand All @@ -46,6 +48,8 @@ This document covers PostgreSQL mathematical, utility, and miscellaneous functio
| reverse (bytea) | REVERSE_BYTES | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\ReverseBytes` |
| row | ROW | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Row` |
| row_to_json | ROW_TO_JSON | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\RowToJson` |
| uuid_extract_timestamp | UUID_EXTRACT_TIMESTAMP | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractTimestamp` |
| uuid_extract_version | UUID_EXTRACT_VERSION | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractVersion` |
| uuidv4 | UUIDV4 | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Uuidv4` |
| uuidv7 | UUIDV7 | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\Uuidv7` |
| xmlagg | XML_AGG | `MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\XmlAgg` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
/**
* Implementation of PostgreSQL to_number().
*
* @see https://www.postgresql.org/docs/17/functions-formatting.html
* Supports Roman numeral conversion via RN pattern (PostgreSQL 18+).
*
* @see https://www.postgresql.org/docs/18/functions-formatting.html
* @since 3.3.0
*/
class ToNumber extends BaseFunction
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL UUID_EXTRACT_TIMESTAMP().
*
* @see https://www.postgresql.org/docs/17/functions-uuid.html
* @since 3.6
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class UuidExtractTimestamp extends BaseFunction
{
protected function customizeFunction(): void
{
$this->setFunctionPrototype('uuid_extract_timestamp(%s)');
$this->addNodeMapping('StringPrimary');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

/**
* Implementation of PostgreSQL UUID_EXTRACT_VERSION().
*
* @see https://www.postgresql.org/docs/17/functions-uuid.html
* @since 3.6
*
* @author Martin Georgiev <martin.georgiev@gmail.com>
*/
class UuidExtractVersion extends BaseFunction
{
protected function customizeFunction(): void
{
$this->setFunctionPrototype('uuid_extract_version(%s)');
$this->addNodeMapping('StringPrimary');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,26 @@ public function tonumber(): void
$this->assertSame('-12454.8', $result[0]['result']);
}

#[Test]
public function tonumber_converts_roman_numerals(): void
{
$this->requirePostgresVersion(180000, 'Roman numeral support in to_number');

$dql = "SELECT to_number('MCMXCIV', 'RN') as result FROM Fixtures\\MartinGeorgiev\\Doctrine\\Entity\\ContainsTexts t WHERE t.id = 1";
$result = $this->executeDqlQuery($dql);
$this->assertSame('1994', $result[0]['result']);
}

#[Test]
public function tonumber_converts_lowercase_roman_numerals(): void
{
$this->requirePostgresVersion(180000, 'Roman numeral support in to_number');

$dql = "SELECT to_number('xlii', 'rn') as result FROM Fixtures\\MartinGeorgiev\\Doctrine\\Entity\\ContainsTexts t WHERE t.id = 1";
$result = $this->executeDqlQuery($dql);
$this->assertSame('42', $result[0]['result']);
}

#[Test]
public function tonumber_throws_with_invalid_format(): void
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractTimestamp;
use PHPUnit\Framework\Attributes\Test;

class UuidExtractTimestampTest extends NumericTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->requirePostgresVersion(170000, 'uuid_extract_timestamp function');
}

protected function getStringFunctions(): array
{
return [
'UUID_EXTRACT_TIMESTAMP' => UuidExtractTimestamp::class,
];
}

#[Test]
public function can_extract_timestamp_from_uuid_v1(): void
{
$dql = "SELECT UUID_EXTRACT_TIMESTAMP('a0eebc99-9c0b-11d1-b465-00c04fd430c8') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);
$timestamp = $result[0]['result'];

$this->assertStringStartsWith('1998-02-02 20:23:12.90287', $timestamp);

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 35 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.
}

#[Test]
public function can_extract_timestamp_from_uuid_v7(): void
{
$dql = "SELECT UUID_EXTRACT_TIMESTAMP('018e7e39-9f42-7000-8000-000000000000') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);
$timestamp = $result[0]['result'];

$this->assertStringStartsWith('2024-03-27 04:44:49.346', $timestamp);

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 1.2

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer latest

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.14 + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM latest + Doctrine Lexer 2.1

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 2.18 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.

Check failure on line 48 in tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/UuidExtractTimestampTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 + Doctrine ORM 3.0 + Doctrine Lexer 3.0

Parameter #2 $string of method PHPUnit\Framework\Assert::assertStringStartsWith() expects string, mixed given.
}

#[Test]
public function returns_null_for_non_timestamped_uuid(): void
{
$dql = "SELECT UUID_EXTRACT_TIMESTAMP('550e8400-e29b-41d4-a716-446655440000') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);

$this->assertNull($result[0]['result']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Tests\Integration\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractVersion;
use PHPUnit\Framework\Attributes\Test;

class UuidExtractVersionTest extends NumericTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->requirePostgresVersion(170000, 'uuid_extract_version function');
}

protected function getStringFunctions(): array
{
return [
'UUID_EXTRACT_VERSION' => UuidExtractVersion::class,
];
}

#[Test]
public function can_extract_version_from_uuid_v1(): void
{
$dql = "SELECT UUID_EXTRACT_VERSION('a0eebc99-9c0b-11d1-b465-00c04fd430c8') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);

$this->assertEquals(1, $result[0]['result']);
}

#[Test]
public function can_extract_version_from_uuid_v4(): void
{
$dql = "SELECT UUID_EXTRACT_VERSION('550e8400-e29b-41d4-a716-446655440000') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);

$this->assertEquals(4, $result[0]['result']);
}

#[Test]
public function can_extract_version_from_uuid_v7(): void
{
$dql = "SELECT UUID_EXTRACT_VERSION('018e7e39-9f42-7000-8000-000000000000') as result
FROM Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsNumerics t
WHERE t.id = 1";

$result = $this->executeDqlQuery($dql);

$this->assertEquals(7, $result[0]['result']);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ protected function getExpectedSqlStatements(): array
{
return [
'converts text to number using format pattern' => "SELECT to_number(c0_.text1, '99G999D9S') AS sclr_0 FROM ContainsTexts c0_",
'converts roman numerals to number' => "SELECT to_number(c0_.text1, 'RN') AS sclr_0 FROM ContainsTexts c0_",
];
}

protected function getDqlStatements(): array
{
return [
'converts text to number using format pattern' => \sprintf("SELECT TO_NUMBER(e.text1, '99G999D9S') FROM %s e", ContainsTexts::class),
'converts roman numerals to number' => \sprintf("SELECT TO_NUMBER(e.text1, 'RN') FROM %s e", ContainsTexts::class),
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsTexts;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractTimestamp;

class UuidExtractTimestampTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'UUID_EXTRACT_TIMESTAMP' => UuidExtractTimestamp::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
'extracts timestamp from uuid' => 'SELECT uuid_extract_timestamp(c0_.text1) AS sclr_0 FROM ContainsTexts c0_',
];
}

protected function getDqlStatements(): array
{
return [
'extracts timestamp from uuid' => \sprintf('SELECT UUID_EXTRACT_TIMESTAMP(e.text1) FROM %s e', ContainsTexts::class),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions;

use Fixtures\MartinGeorgiev\Doctrine\Entity\ContainsTexts;
use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\UuidExtractVersion;

class UuidExtractVersionTest extends TestCase
{
protected function getStringFunctions(): array
{
return [
'UUID_EXTRACT_VERSION' => UuidExtractVersion::class,
];
}

protected function getExpectedSqlStatements(): array
{
return [
'extracts version from uuid' => 'SELECT uuid_extract_version(c0_.text1) AS sclr_0 FROM ContainsTexts c0_',
];
}

protected function getDqlStatements(): array
{
return [
'extracts version from uuid' => \sprintf('SELECT UUID_EXTRACT_VERSION(e.text1) FROM %s e', ContainsTexts::class),
];
}
}
Loading