cli-barcode PHP
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

73 行
2.2 KiB

  1. <?php
  2. namespace Ulrichsg\Getopt;
  3. class OptionTest extends \PHPUnit_Framework_TestCase
  4. {
  5. public function testConstruct()
  6. {
  7. $option = new Option('a', 'az-AZ09_', Getopt::OPTIONAL_ARGUMENT);
  8. $this->assertEquals('a', $option->short());
  9. $this->assertEquals('az-AZ09_', $option->long());
  10. $this->assertEquals(Getopt::OPTIONAL_ARGUMENT, $option->mode());
  11. }
  12. public function testConstructEmptyOption()
  13. {
  14. $this->setExpectedException('InvalidArgumentException');
  15. new Option(null, null, Getopt::NO_ARGUMENT);
  16. }
  17. public function testConstructNoLetter()
  18. {
  19. $this->setExpectedException('InvalidArgumentException');
  20. new Option('?', null, Getopt::NO_ARGUMENT);
  21. }
  22. public function testConstructInvalidCharacter()
  23. {
  24. $this->setExpectedException('InvalidArgumentException');
  25. new Option(null, 'öption', Getopt::NO_ARGUMENT);
  26. }
  27. public function testConstructInvalidArgumentType()
  28. {
  29. $this->setExpectedException('InvalidArgumentException');
  30. new Option('a', null, 'no_argument');
  31. }
  32. public function testConstructLongOptionTooShort()
  33. {
  34. $this->setExpectedException('InvalidArgumentException');
  35. new Option(null, 'a', Getopt::REQUIRED_ARGUMENT);
  36. }
  37. public function testSetArgument()
  38. {
  39. $option = new Option('a', null, Getopt::OPTIONAL_ARGUMENT);
  40. $this->assertEquals($option, $option->setArgument(new Argument()));
  41. $this->assertInstanceof('Ulrichsg\Getopt\Argument', $option->getArgument());
  42. }
  43. public function testSetArgumentWrongMode()
  44. {
  45. $this->setExpectedException('InvalidArgumentException');
  46. $option = new Option('a', null, Getopt::NO_ARGUMENT);
  47. $option->setArgument(new Argument());
  48. }
  49. public function testSetDefaultValue()
  50. {
  51. $option = new Option('a', null, Getopt::OPTIONAL_ARGUMENT);
  52. $this->assertEquals($option, $option->setDefaultValue(10));
  53. $this->assertEquals(10, $option->getArgument()->getDefaultValue());
  54. }
  55. public function testSetValidation()
  56. {
  57. $option = new Option('a', null, Getopt::OPTIONAL_ARGUMENT);
  58. $this->assertEquals($option, $option->setValidation('is_numeric'));
  59. $this->assertTrue($option->getArgument()->hasValidation());
  60. }
  61. }