| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- namespace Test\Michel\Console;
- use Michel\Console\Argument\CommandArgument;
- use Michel\Console\Output;
- use Michel\UniTester\TestCase;
- class CommandArgumentTest extends TestCase
- {
- protected function setUp(): void
- {
- // TODO: Implement setUp() method.
- }
- protected function tearDown(): void
- {
- // TODO: Implement tearDown() method.
- }
- protected function execute(): void
- {
- $this->testValidateThrowsExceptionIfRequiredAndValueIsEmpty();
- $this->testValidateDoesNotThrowExceptionIfNotRequiredAndValueIsEmpty();
- $this->testValidateDoesNotThrowExceptionIfRequiredAndValueIsNotEmpty();
- $this->testGetNameReturnsCorrectValue();
- $this->testIsRequiredReturnsCorrectValue();
- $this->testGetDefaultValueReturnsCorrectValue();
- $this->testGetDescriptionReturnsCorrectValue();
- }
- public function testValidateThrowsExceptionIfRequiredAndValueIsEmpty()
- {
- $arg = new CommandArgument('test', true);
- $this->expectException(\InvalidArgumentException::class, function () use ($arg) {
- $arg->validate('');
- }, 'The required argument "test" was not provided.');
- }
- public function testValidateDoesNotThrowExceptionIfNotRequiredAndValueIsEmpty()
- {
- $arg = new CommandArgument('test');
- $arg->validate('');
- $this->assertTrue(true);
- }
- public function testValidateDoesNotThrowExceptionIfRequiredAndValueIsNotEmpty()
- {
- $arg = new CommandArgument('test', true);
- $arg->validate('value');
- $this->assertTrue(true);
- }
- public function testGetNameReturnsCorrectValue()
- {
- $arg = new CommandArgument('test');
- $this->assertEquals('test', $arg->getName());
- }
- public function testIsRequiredReturnsCorrectValue()
- {
- $arg = new CommandArgument('test', true);
- $this->assertTrue($arg->isRequired());
- $arg = new CommandArgument('test');
- $this->assertFalse($arg->isRequired());
- }
- public function testGetDefaultValueReturnsCorrectValue()
- {
- $arg = new CommandArgument('test', false, 'default');
- $this->assertEquals('default', $arg->getDefaultValue());
- }
- public function testGetDescriptionReturnsCorrectValue()
- {
- $arg = new CommandArgument('test', false, null, 'description');
- $this->assertEquals('description', $arg->getDescription());
- }
- }
|