|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace RayanLevert\Cli\Tests\Arguments; |
| 4 | + |
| 5 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 6 | +use PHPUnit\Framework\Attributes\Test; |
| 7 | +use RayanLevert\Cli\Arguments\Option; |
| 8 | + |
| 9 | +#[CoversClass(Option::class)] |
| 10 | +class OptionTest extends \PHPUnit\Framework\TestCase |
| 11 | +{ |
| 12 | + #[Test] |
| 13 | + public function verifiesType(): void |
| 14 | + { |
| 15 | + $this->assertTrue(Option::DESCRIPTION->verifiesType('A description')); |
| 16 | + $this->assertTrue(Option::REQUIRED->verifiesType(true)); |
| 17 | + $this->assertTrue(Option::NO_VALUE->verifiesType(false)); |
| 18 | + $this->assertTrue(Option::PREFIX->verifiesType('-u=')); |
| 19 | + $this->assertTrue(Option::LONG_PREFIX->verifiesType('--user=')); |
| 20 | + $this->assertTrue(Option::CAST_TO->verifiesType('int')); |
| 21 | + $this->assertTrue(Option::DEFAULT_VALUE->verifiesType('default')); |
| 22 | + $this->assertTrue(Option::DEFAULT_VALUE->verifiesType(42)); |
| 23 | + $this->assertTrue(Option::DEFAULT_VALUE->verifiesType(3.14)); |
| 24 | + |
| 25 | + $this->assertFalse(Option::DESCRIPTION->verifiesType(true)); |
| 26 | + $this->assertFalse(Option::REQUIRED->verifiesType('yes')); |
| 27 | + $this->assertFalse(Option::NO_VALUE->verifiesType('no')); |
| 28 | + $this->assertFalse(Option::PREFIX->verifiesType(123)); |
| 29 | + $this->assertFalse(Option::LONG_PREFIX->verifiesType(456.78)); |
| 30 | + $this->assertFalse(Option::CAST_TO->verifiesType(false)); |
| 31 | + $this->assertFalse(Option::DEFAULT_VALUE->verifiesType([])); |
| 32 | + } |
| 33 | + |
| 34 | + #[Test] |
| 35 | + public function getPhpProperty(): void |
| 36 | + { |
| 37 | + $this->assertSame('description', Option::DESCRIPTION->getPhpProperty()); |
| 38 | + $this->assertSame('isRequired', Option::REQUIRED->getPhpProperty()); |
| 39 | + $this->assertSame('noValue', Option::NO_VALUE->getPhpProperty()); |
| 40 | + $this->assertSame('prefix', Option::PREFIX->getPhpProperty()); |
| 41 | + $this->assertSame('longPrefix', Option::LONG_PREFIX->getPhpProperty()); |
| 42 | + $this->assertSame('castTo', Option::CAST_TO->getPhpProperty()); |
| 43 | + $this->assertSame('defaultValue', Option::DEFAULT_VALUE->getPhpProperty()); |
| 44 | + } |
| 45 | +} |
0 commit comments