EnumTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @CreateTime: 2019/9/9 下午05:47
  4. * @Author: huizhang <tuzisir@163.com>
  5. * @Copyright: copyright(2019) Easyswoole all rights reserved
  6. * @Description: SplEnum 单元测试
  7. */
  8. namespace EasySwoole\Spl\Test;
  9. use EasySwoole\Spl\Test\Enum\Month;
  10. use PHPUnit\Framework\TestCase;
  11. class EnumTest extends TestCase {
  12. public function testConstruct() {
  13. $month = new Month(1);
  14. $this->assertEquals(
  15. 'JANUARY',
  16. $month->getName()
  17. );
  18. }
  19. public function testGetName() {
  20. $month = new Month(1);
  21. $this->assertEquals(
  22. 'JANUARY',
  23. $month->getName()
  24. );
  25. }
  26. public function testGetValue() {
  27. $month = new Month(1);
  28. $this->assertEquals(
  29. 1,
  30. $month->getValue()
  31. );
  32. }
  33. public function testIsValidName() {
  34. $this->assertTrue(
  35. Month::isValidName('JANUARY')
  36. );
  37. }
  38. public function testIsValidValue() {
  39. $this->assertEquals(
  40. 'JANUARY',
  41. Month::isValidValue(1)
  42. );
  43. }
  44. public function testGetEnumList() {
  45. $this->assertEquals(
  46. [
  47. 'JANUARY' => 1,
  48. 'FEBRUARY' => 2,
  49. 'MARCH' => 3,
  50. 'APRIL' => 4,
  51. 'MAY' => 5,
  52. 'JUNE' => 6,
  53. 'JULY' => 7,
  54. 'AUGUST' => 8,
  55. 'SEPTEMBER' => 9,
  56. 'OCTOBER' => 10,
  57. 'NOVEMBER' => 11,
  58. 'DECEMBER' => 12,
  59. ],
  60. Month::getEnumList()
  61. );
  62. }
  63. }