| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Tests\Filter\DoctrineFilter;
- use App\Filter\DoctrineFilter\DateTimeFilter;
- use App\Tests\TestToolsTrait;
- use Doctrine\ORM\EntityManagerInterface;
- use PHPUnit\Framework\TestCase;
- class DateTimeFilterTest extends TestCase
- {
- use TestToolsTrait;
- private DateTimeFilter $dateTimeFilter;
- public function setUp(): void
- {
- $em = $this->getMockBuilder(EntityManagerInterface::class)->disableOriginalConstructor()->getMock();
- $this->dateTimeFilter = new DateTimeFilter($em);
- }
- /**
- * @see DateTimeFilter::constructQuery()
- */
- public function testConstructQuery():void
- {
- $queryExpected = "(o.startDate <= '2021-12-20') AND (o.endDate > '2021-12-20' OR o.endDate IS NULL)";
- $this->assertEquals($queryExpected, $this->invokeMethod($this->dateTimeFilter, 'constructQuery', [
- [
- 'start' => [
- '2021-12-20' => [4]
- ],
- 'end' => [
- '2021-12-20' => [5],
- 'NULL' => [0]
- ]
- ],
- 'o',
- [
- 'start' => 'startDate',
- 'end' => 'endDate'
- ]
- ]));
- $queryExpected = "(o.startDate < '2021-12-20' OR o.startDate > '2021-12-30') AND (o.endDate < '2022-01-20')";
- $this->assertEquals($queryExpected, $this->invokeMethod($this->dateTimeFilter, 'constructQuery', [
- [
- 'start' => [
- '2021-12-20' => [1],
- '2021-12-30' => [5]
- ],
- 'end' => [
- '2022-01-20' => [1]
- ]
- ],
- 'o',
- [
- 'start' => 'startDate',
- 'end' => 'endDate'
- ]
- ]));
- }
- /**
- * @see DateTimeFilter::getArithmeticValue()
- */
- public function testGetArithmeticValue():void
- {
- $this->assertEquals('<', $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [1]));
- $this->assertEquals('<=', $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [4]));
- $this->assertEquals('=', $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [3]));
- $this->assertEquals('>=', $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [8]));
- $this->assertEquals('>', $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [5]));
- $this->assertEquals(null, $this->invokeMethod($this->dateTimeFilter, 'getArithmeticValue', [0]));
- }
- }
|