packages/sql-semantics-mysql/tests/Unit/Statement/Name/AccountTest.php
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Unit\Statement\Name;
6
7use PHPUnit\Framework\Attributes\CoversNothing;
8use PHPUnit\Framework\Attributes\Small;
9use PHPUnit\Framework\TestCase;
10use SqlSemantics\Platform\MySql\Lowering\Lowering;
11use SqlSemantics\Platform\MySql\Model\Contract\ParameterStyle;
12use SqlSemantics\Platform\MySql\Model\Lowering\Leaves;
13use SqlSemantics\Platform\MySql\Model\Statement\Identifier\Name;
14use SqlSemantics\Platform\MySql\Platform;
15use SqlSemantics\Platform\MySql\Statement\Name\Account;
16use SqlSemantics\Platform\MySql\Statement\Name\AccountName;
17use SqlSemantics\Platform\MySql\Statement\Name\CurrentUser;
18
19#[CoversNothing]
20#[Small]
21final class AccountTest extends TestCase
22{
23 public function testBothKindsOfAccountImplementTheInterface(): void
24 {
25 $platform = new Platform();
26 $profile = $platform->profile('mysql-8.4.7', null, ParameterStyle::Native);
27 $nodes = $platform->parser($profile)->parse('DROP USER bob@localhost, CURRENT_USER()')->find('user');
28 $lowering = new Lowering($platform->productions($profile), new Leaves(), $profile);
29 $written = $lowering->users->account($nodes[0]);
30 $current = $lowering->users->account($nodes[1]);
31
32 self::assertInstanceOf(AccountName::class, $written);
33 self::assertInstanceOf(CurrentUser::class, $current);
34 self::assertContainsOnlyInstancesOf(Account::class, [new AccountName(new Name('bob')), new CurrentUser()]);
35 }
36}
37