mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 07:03:49 +00:00
DX: Add DQL function LEAST and GREATEST
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Doctrine\DQL;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class GreatestTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testGreatestInDQL()
|
||||
{
|
||||
$dql = 'SELECT GREATEST(a.validFrom, a.validTo, :now) AS g FROM ' . Address::class . ' a WHERE a.validTo < :now and a.validFrom < :now';
|
||||
|
||||
$actual = $this->entityManager
|
||||
->createQuery($dql)
|
||||
->setParameter('now', $now = new DateTimeImmutable('now'), Types::DATE_IMMUTABLE)
|
||||
->setMaxResults(3)
|
||||
->getResult();
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertEquals($now->format('Y-m-d'), $actual[0]['g']);
|
||||
}
|
||||
}
|
48
src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/LeastTest.php
Normal file
48
src/Bundle/ChillMainBundle/Tests/Doctrine/DQL/LeastTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Tests\Doctrine\DQL;
|
||||
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @coversNothing
|
||||
*/
|
||||
final class LeastTest extends KernelTestCase
|
||||
{
|
||||
private EntityManagerInterface $entityManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->entityManager = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testGreatestInDQL()
|
||||
{
|
||||
$dql = 'SELECT LEAST(a.validFrom, a.validTo, :now) AS g FROM ' . Address::class . ' a WHERE a.validTo < :now and a.validFrom < :now';
|
||||
|
||||
$actual = $this->entityManager
|
||||
->createQuery($dql)
|
||||
->setParameter('now', $now = new DateTimeImmutable('now'), Types::DATE_IMMUTABLE)
|
||||
->setMaxResults(3)
|
||||
->getResult();
|
||||
|
||||
$this->assertIsArray($actual);
|
||||
$this->assertNotEquals($now->format('Y-m-d'), $actual[0]['g']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user