packages/sql-semantics-mysql/tests/Unit/Lowering/Expression/IntervalRuleTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Lowering\Expression;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Lowering\Expression\IntervalRule;
11use SqlSemantics\Platform\MySql\Lowering\Lowering;
12use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
13use SqlSemantics\Platform\MySql\Model\Lowering\Leaves;
14use SqlSemantics\Platform\MySql\Platform;
15use SqlSemantics\Platform\MySql\Statement\Expression\IntervalUnit;
16
17#[CoversClass(IntervalRule::class)]
18#[Medium]
19final class IntervalRuleTest extends TestCase
20{
21 public function testUnitLowersSimpleAndCompoundUnits(): void
22 {
23 $platform = new Platform();
24 $profile = $platform->profile('mysql-5.6.51', null, ParameterStyle::Native);
25 $lowering = new Lowering($platform->productions($profile), new Leaves(), $profile);
26 $rule = new IntervalRule($lowering);
27
28 self::assertSame(IntervalUnit::MinuteMicrosecond, $rule->unit($platform->parser($profile)->parse("SELECT 1 + INTERVAL '1' MINUTE_MICROSECOND")->find('interval')[0]));
29 self::assertSame(IntervalUnit::Day, $rule->unit($platform->parser($profile)->parse('SELECT 1 + INTERVAL 1 SQL_TSI_DAY')->find('interval')[0]));
30 }
31}
32