Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

LuMethodDocParserTest.php 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. use Luticate\Utils\Business\LuMethodDocParser;
  3. /**
  4. * Created by PhpStorm.
  5. * User: robin
  6. * Date: 5/29/16
  7. * Time: 7:52 PM
  8. */
  9. class LuDocParserTest extends \PHPUnit_Framework_TestCase
  10. {
  11. public function testSimpleSummary()
  12. {
  13. $doc = new LuMethodDocParser("/**
  14. * Get all data
  15. */");
  16. $doc->parse();
  17. $this->assertSame("Get all data\n", $doc->getSummary());
  18. }
  19. public function testSimpleSummaryMultiLine()
  20. {
  21. $doc = new LuMethodDocParser("/**
  22. * Get all data
  23. * Using the database
  24. */");
  25. $doc->parse();
  26. $this->assertSame("Get all data\nUsing the database\n", $doc->getSummary());
  27. }
  28. public function testSimpleParam()
  29. {
  30. $doc = new LuMethodDocParser('/**
  31. * Get all data
  32. * @param $myvar MyType some doc
  33. * @param MyType $myvar2 some other doc
  34. */');
  35. $doc->parse();
  36. $this->assertSame("Get all data\n", $doc->getSummary());
  37. $params = [];
  38. foreach ($doc->getParams() as $param) {
  39. $params[] = $param->jsonSerialize();
  40. }
  41. $expectedParams = [
  42. ["NotNull" => true, "Summary" => "some doc\n", "Type" => "MyType", "Name" => 'myvar',
  43. "Constraints" => []],
  44. ["NotNull" => true, "Summary" => "some other doc\n", "Type" => "MyType", "Name" => 'myvar2',
  45. "Constraints" => []]
  46. ];
  47. $this->assertSame($expectedParams, $params);
  48. }
  49. public function testSimpleParamMultiLine()
  50. {
  51. $doc = new LuMethodDocParser('/**
  52. * Get all data
  53. * @param $myvar MyType some doc
  54. * @param MyType $myvar2 some other doc
  55. * on another line
  56. */');
  57. $doc->parse();
  58. $this->assertSame("Get all data\n", $doc->getSummary());
  59. $params = [];
  60. foreach ($doc->getParams() as $name => $param) {
  61. $params[$name] = $param->jsonSerialize();
  62. }
  63. $expectedParams = [
  64. 'myvar' => ["NotNull" => true, "Summary" => "some doc\n", "Type" => "MyType", "Name" => 'myvar',
  65. "Constraints" => []],
  66. 'myvar2' => ["NotNull" => true, "Summary" => "some other doc\non another line\n", "Type" => "MyType",
  67. "Name" => 'myvar2', "Constraints" => []]
  68. ];
  69. $this->assertSame($expectedParams, $params);
  70. }
  71. public function testAll()
  72. {
  73. $doc = new LuMethodDocParser('/**
  74. * Get all data
  75. * On another line
  76. * @param $myvar MyType some doc
  77. * Too much doc
  78. * @param MyType $myvar2 some other doc
  79. * on another line
  80. * @nullable
  81. * @min 42
  82. * @max 42
  83. * @between 0 42
  84. * @another 1 2 42.42 true false "a string" \'string\' null
  85. * and another
  86. * @return AnotherType
  87. */');
  88. $doc->parse();
  89. $this->assertSame("Get all data\nOn another line\n", $doc->getSummary());
  90. $this->assertSame("AnotherType", $doc->getReturnType());
  91. $params = [];
  92. foreach ($doc->getParams() as $name => $param) {
  93. $params[$name] = $param->jsonSerialize();
  94. }
  95. $expectedParams = [
  96. 'myvar' => ["NotNull" => true, "Summary" => "some doc\nToo much doc\n", "Type" => "MyType",
  97. "Name" => 'myvar', "Constraints" => []],
  98. 'myvar2' => ["NotNull" => false, "Summary" => "some other doc\non another line\nand another\n",
  99. "Type" => "MyType", "Name" => 'myvar2',
  100. "Constraints" => [
  101. ["Method" => "min", "Arguments" => [42]],
  102. ["Method" => "max", "Arguments" => [42]],
  103. ["Method" => "between", "Arguments" => [0, 42]],
  104. ["Method" => "another", "Arguments" => [1, 2, 42.42, true, false, "a string", "string", null]]
  105. ]
  106. ]
  107. ];
  108. $this->assertSame($expectedParams, $params);
  109. }
  110. }