ManagerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace League\CLImate\Tests\Argument;
  3. use League\CLImate\Argument\Argument;
  4. use League\CLImate\Argument\Manager;
  5. use PHPUnit\Framework\TestCase;
  6. class ManagerTest extends TestCase
  7. {
  8. private $manager;
  9. public function setUp(): void
  10. {
  11. $this->manager = new Manager;
  12. }
  13. public function testDefined1()
  14. {
  15. $argument = Argument::createFromArray("test", [
  16. "prefix" => "t",
  17. "longPrefix" => "test",
  18. ]);
  19. $this->manager->add($argument);
  20. $result = $this->manager->defined("test", ["command", "--test"]);
  21. $this->assertTrue($result);
  22. }
  23. public function testDefined2()
  24. {
  25. $result = $this->manager->defined("test");
  26. $this->assertFalse($result);
  27. }
  28. public function testDefined3()
  29. {
  30. $argument = Argument::createFromArray("lorem", [
  31. "prefix" => "l",
  32. "longPrefix" => "Лорем",
  33. ]);
  34. $this->manager->add($argument);
  35. $result = $this->manager->defined("lorem", ["command", "--Лорем"]);
  36. $this->assertTrue($result);
  37. }
  38. public function testItParsesAnOptionalArgument()
  39. {
  40. $this->manager->add([
  41. 'foo' => ['prefix' => 'f'],
  42. 'bar' => ['prefix' => 'b']
  43. ]);
  44. $this->manager->parse(['command', '-f', '-b', 'abc']);
  45. $this->assertEquals('', $this->manager->get('foo'));
  46. }
  47. public function testItStoresTrailingInArray()
  48. {
  49. $this->manager->add([
  50. 'foo' => ['prefix' => 'f']
  51. ]);
  52. $this->manager->parse(['command', '-f', '--', 'test', 'trailing with spaces']);
  53. $this->assertEquals('test trailing with spaces', $this->manager->trailing());
  54. $this->assertEquals(['test', 'trailing with spaces'], $this->manager->trailingArray());
  55. }
  56. }