packages/sql-semantics-mysql/tests/Unit/Rules/Account/NumberChecksTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Rules\Account;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Rules\Account\NumberChecks;
11use SqlSemantics\Platform\MySql\Semantics;
12use SqlSemantics\Platform\MySql\Statement\Account\Problem\NumberOutOfRange;
13use SqlSemantics\Platform\MySql\Statement\Literal\Numeral;
14
15#[CoversClass(NumberChecks::class)]
16#[Medium]
17final class NumberChecksTest extends TestCase
18{
19 public function testValueComputesTheExactDecimal(): void
20 {
21 $checks = new NumberChecks();
22
23 self::assertSame(['18446744073709551615', '7', '0', null], [$checks->value(new Numeral('FFFFFFFFFFFFFFFF', true)), $checks->value(new Numeral('007')), $checks->value(new Numeral('000')), $checks->value(new Numeral('1.5'))]);
24 }
25
26 public function testCompareOrdersByLengthThenDigits(): void
27 {
28 self::assertSame([true, true, true], [(new NumberChecks())->compare('9', '10') < 0, (new NumberChecks())->compare('20', '19') > 0, (new NumberChecks())->compare('5', '5') === 0]);
29 }
30
31 public function testRangeReportsANumberOutsideTheRange(): void
32 {
33 $semantics = new Semantics();
34
35 self::assertSame('The value 65536 is not accepted for DAY (ER_WRONG_VALUE).', $semantics->inspect('CREATE USER u PASSWORD EXPIRE INTERVAL 65536 DAY')->facts->diagnostics[0]->message());
36 self::assertSame([], $semantics->inspect('CREATE USER u PASSWORD EXPIRE INTERVAL 65535 DAY')->facts->diagnostics);
37 }
38
39 public function testFactorReportsAFactorOtherThanTwoAndThree(): void
40 {
41 self::assertInstanceOf(NumberOutOfRange::class, (new Semantics())->inspect('ALTER USER u 02 FACTOR UNREGISTER')->facts->diagnostics[0]);
42 }
43}
44