2
0

InputTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace Test\Michel\Console;
  3. use Michel\Console\Input;
  4. use Michel\UniTester\TestCase;
  5. class InputTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. // TODO: Implement setUp() method.
  10. }
  11. protected function tearDown(): void
  12. {
  13. // TODO: Implement tearDown() method.
  14. }
  15. protected function execute(): void
  16. {
  17. $this->testGetCommandName();
  18. $this->testGetOptions();
  19. $this->testGetArguments();
  20. $this->testHasOption();
  21. $this->testHasArgument();
  22. $this->testGetOptionValue();
  23. $this->testGetArgumentValue();
  24. }
  25. public function testGetCommandName()
  26. {
  27. $input = new Input('test', [], []);
  28. $this->assertEquals('test', $input->getCommandName());
  29. }
  30. public function testGetOptions()
  31. {
  32. $options = ['--option1' => 'value1', '--option2' => 'value2'];
  33. $input = new Input('test', $options, []);
  34. $this->assertEquals($options, $input->getOptions());
  35. }
  36. public function testGetArguments()
  37. {
  38. $arguments = ['argument1' => 'value1', 'argument2' => 'value2'];
  39. $input = new Input('test', [], $arguments);
  40. $this->assertEquals($arguments, $input->getArguments());
  41. }
  42. public function testHasOption()
  43. {
  44. $input = new Input('test', ['--option' => 'value'], []);
  45. $this->assertTrue($input->hasOption('option'));
  46. $this->assertTrue($input->hasOption('--option'));
  47. $this->assertFalse($input->hasOption('invalid'));
  48. }
  49. public function testGetOptionValue()
  50. {
  51. $input = new Input('test', ['--option' => 'value'], []);
  52. $this->assertEquals('value', $input->getOptionValue('option'));
  53. $this->assertEquals('value', $input->getOptionValue('--option'));
  54. $this->assertEquals(null, $input->getOptionValue('invalid'));
  55. }
  56. public function testGetArgumentValue()
  57. {
  58. $input = new Input('test', [], ['--argument' => 'value']);
  59. $this->assertEquals('value', $input->getArgumentValue('argument'));
  60. $this->expectException(\InvalidArgumentException::class, function () use ($input) {
  61. $input->getArgumentValue('invalid');
  62. });
  63. }
  64. public function testHasArgument()
  65. {
  66. $input = new Input('test', [], ['--argument' => 'value']);
  67. $this->assertTrue($input->hasArgument('argument'));
  68. $this->assertFalse($input->hasArgument('invalid'));
  69. }
  70. }