2
0

CommandArgumentTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace Test\Michel\Console;
  3. use Michel\Console\Argument\CommandArgument;
  4. use Michel\Console\Output;
  5. use Michel\UniTester\TestCase;
  6. class CommandArgumentTest extends TestCase
  7. {
  8. protected function setUp(): void
  9. {
  10. // TODO: Implement setUp() method.
  11. }
  12. protected function tearDown(): void
  13. {
  14. // TODO: Implement tearDown() method.
  15. }
  16. protected function execute(): void
  17. {
  18. $this->testValidateThrowsExceptionIfRequiredAndValueIsEmpty();
  19. $this->testValidateDoesNotThrowExceptionIfNotRequiredAndValueIsEmpty();
  20. $this->testValidateDoesNotThrowExceptionIfRequiredAndValueIsNotEmpty();
  21. $this->testGetNameReturnsCorrectValue();
  22. $this->testIsRequiredReturnsCorrectValue();
  23. $this->testGetDefaultValueReturnsCorrectValue();
  24. $this->testGetDescriptionReturnsCorrectValue();
  25. }
  26. public function testValidateThrowsExceptionIfRequiredAndValueIsEmpty()
  27. {
  28. $arg = new CommandArgument('test', true);
  29. $this->expectException(\InvalidArgumentException::class, function () use ($arg) {
  30. $arg->validate('');
  31. }, 'The required argument "test" was not provided.');
  32. }
  33. public function testValidateDoesNotThrowExceptionIfNotRequiredAndValueIsEmpty()
  34. {
  35. $arg = new CommandArgument('test');
  36. $arg->validate('');
  37. $this->assertTrue(true);
  38. }
  39. public function testValidateDoesNotThrowExceptionIfRequiredAndValueIsNotEmpty()
  40. {
  41. $arg = new CommandArgument('test', true);
  42. $arg->validate('value');
  43. $this->assertTrue(true);
  44. }
  45. public function testGetNameReturnsCorrectValue()
  46. {
  47. $arg = new CommandArgument('test');
  48. $this->assertEquals('test', $arg->getName());
  49. }
  50. public function testIsRequiredReturnsCorrectValue()
  51. {
  52. $arg = new CommandArgument('test', true);
  53. $this->assertTrue($arg->isRequired());
  54. $arg = new CommandArgument('test');
  55. $this->assertFalse($arg->isRequired());
  56. }
  57. public function testGetDefaultValueReturnsCorrectValue()
  58. {
  59. $arg = new CommandArgument('test', false, 'default');
  60. $this->assertEquals('default', $arg->getDefaultValue());
  61. }
  62. public function testGetDescriptionReturnsCorrectValue()
  63. {
  64. $arg = new CommandArgument('test', false, null, 'description');
  65. $this->assertEquals('description', $arg->getDescription());
  66. }
  67. }