. */ declare(strict_types=1); namespace App\Tests\Doctrine\Functions; use App\Doctrine\Functions\Natsort; use Doctrine\DBAL\Platforms\MariaDBPlatform; use Doctrine\DBAL\Platforms\MySQLPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SQLitePlatform; final class NatsortTest extends AbstractDoctrineFunctionTestCase { protected function setUp(): void { parent::setUp(); Natsort::allowSlowNaturalSort(false); $this->setStaticProperty(Natsort::class, 'supportsNaturalSort', null); } public function testNatsortUsesPostgresCollation(): void { $function = new Natsort('NATSORT'); $this->setObjectProperty($function, 'field', $this->createNode('part_name')); $sql = $function->getSql($this->createSqlWalker(new PostgreSQLPlatform())); $this->assertSame('part_name COLLATE numeric', $sql); } public function testNatsortUsesMariaDbNativeFunctionOnSupportedVersion(): void { $function = new Natsort('NATSORT'); $this->setObjectProperty($function, 'field', $this->createNode('part_name')); $sql = $function->getSql($this->createSqlWalker(new MariaDBPlatform(), '10.11.2-MariaDB')); $this->assertSame('NATURAL_SORT_KEY(part_name)', $sql); } public function testNatsortFallsBackWithoutSlowSort(): void { $function = new Natsort('NATSORT'); $this->setObjectProperty($function, 'field', $this->createNode('part_name')); $sql = $function->getSql($this->createSqlWalker(new MariaDBPlatform(), '10.6.10-MariaDB')); $this->assertSame('part_name', $sql); } public function testNatsortUsesSlowSortFunctionOnMySqlWhenEnabled(): void { Natsort::allowSlowNaturalSort(); $function = new Natsort('NATSORT'); $this->setObjectProperty($function, 'field', $this->createNode('part_name')); $sql = $function->getSql($this->createSqlWalker(new MySQLPlatform())); $this->assertSame('NatSortKey(part_name, 0)', $sql); } public function testNatsortUsesSlowSortCollationOnSqliteWhenEnabled(): void { Natsort::allowSlowNaturalSort(); $function = new Natsort('NATSORT'); $this->setObjectProperty($function, 'field', $this->createNode('part_name')); $sql = $function->getSql($this->createSqlWalker(new SQLitePlatform())); $this->assertSame('part_name COLLATE NATURAL_CMP', $sql); } }