|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the playwright-php/playwright package. |
| 7 | + * For the full copyright and license information, please view |
| 8 | + * the LICENSE file that was distributed with this source code. |
| 9 | + */ |
| 10 | + |
| 11 | +namespace PlaywrightPHP\Tests\Unit\Input; |
| 12 | + |
| 13 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 14 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | +use PlaywrightPHP\Exception\InvalidArgumentException; |
| 17 | +use PlaywrightPHP\Input\ModifierKey; |
| 18 | + |
| 19 | +#[CoversClass(ModifierKey::class)] |
| 20 | +final class ModifierKeyTest extends TestCase |
| 21 | +{ |
| 22 | + public function testEnumValues(): void |
| 23 | + { |
| 24 | + $this->assertSame('Alt', ModifierKey::Alt->value); |
| 25 | + $this->assertSame('Control', ModifierKey::Control->value); |
| 26 | + $this->assertSame('Meta', ModifierKey::Meta->value); |
| 27 | + $this->assertSame('Shift', ModifierKey::Shift->value); |
| 28 | + } |
| 29 | + |
| 30 | + #[DataProvider('provideFromStringData')] |
| 31 | + public function testFromString(ModifierKey $expected, string $input): void |
| 32 | + { |
| 33 | + $this->assertSame($expected, ModifierKey::fromString($input)); |
| 34 | + } |
| 35 | + |
| 36 | + public static function provideFromStringData(): array |
| 37 | + { |
| 38 | + return [ |
| 39 | + 'alt lowercase' => [ModifierKey::Alt, 'alt'], |
| 40 | + 'alt uppercase' => [ModifierKey::Alt, 'Alt'], |
| 41 | + 'control lowercase' => [ModifierKey::Control, 'control'], |
| 42 | + 'control uppercase' => [ModifierKey::Control, 'Control'], |
| 43 | + 'control short' => [ModifierKey::Control, 'ctrl'], |
| 44 | + 'meta lowercase' => [ModifierKey::Meta, 'meta'], |
| 45 | + 'meta uppercase' => [ModifierKey::Meta, 'Meta'], |
| 46 | + 'meta cmd' => [ModifierKey::Meta, 'cmd'], |
| 47 | + 'meta command' => [ModifierKey::Meta, 'command'], |
| 48 | + 'shift lowercase' => [ModifierKey::Shift, 'shift'], |
| 49 | + 'shift uppercase' => [ModifierKey::Shift, 'Shift'], |
| 50 | + ]; |
| 51 | + } |
| 52 | + |
| 53 | + public function testFromStringWithInvalidModifier(): void |
| 54 | + { |
| 55 | + $this->expectException(InvalidArgumentException::class); |
| 56 | + $this->expectExceptionMessage('Unknown modifier key: "invalid".'); |
| 57 | + |
| 58 | + ModifierKey::fromString('invalid'); |
| 59 | + } |
| 60 | +} |
0 commit comments