packages/sql-semantics-sqlite/tests/Unit/Statement/Query/Problem/WrongArgumentCountTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Query\Problem;
6
7use PHPUnit\Framework\Attributes\CoversClass;
8use PHPUnit\Framework\Attributes\Medium;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\Sqlite\Model\Statement\Identifier\Name;
11use SqlSemantics\Platform\Sqlite\Semantics;
12use SqlSemantics\Platform\Sqlite\Statement\Query\Problem\WrongArgumentCount;
13
14#[CoversClass(WrongArgumentCount::class)]
15#[Medium]
16final class WrongArgumentCountTest extends TestCase
17{
18 public function testMessageNamesTheFunction(): void
19 {
20 $problem = new WrongArgumentCount(new Name('Abs'), 2);
21
22 self::assertSame('wrong number of arguments to function Abs()', $problem->message());
23 self::assertSame(2, $problem->arguments);
24 self::assertSame('Abs', $problem->function->value);
25 }
26
27 public function testMessageIsReportedForACallWithTooManyArguments(): void
28 {
29 $query = (new Semantics())->inspect('SELECT abs(1, 2)');
30
31 self::assertInstanceOf(WrongArgumentCount::class, $query->facts->diagnostics[0]);
32 self::assertSame(2, $query->facts->diagnostics[0]->arguments);
33 self::assertSame('wrong number of arguments to function abs()', $query->facts->diagnostics[0]->message());
34 }
35}
36