Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

LuMethodDocParserTest.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\n",
  43. "Constraints" => []],
  44. ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\n",
  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' => ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\n",
  65. "Constraints" => []],
  66. 'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\n",
  67. "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. * @min 42
  81. * @max 42
  82. * @between 0 42
  83. * @another 1 2 42.42 true false "a string" \'string\' null
  84. * and another
  85. * @return AnotherType
  86. */');
  87. $doc->parse();
  88. $this->assertSame("Get all data\nOn another line\n", $doc->getSummary());
  89. $this->assertSame("AnotherType", $doc->getReturnType());
  90. $params = [];
  91. foreach ($doc->getParams() as $name => $param) {
  92. $params[$name] = $param->jsonSerialize();
  93. }
  94. $expectedParams = [
  95. 'myvar' => ["Name" => 'myvar', "Type" => "MyType", "Summary" => "some doc\nToo much doc\n",
  96. "Constraints" => []],
  97. 'myvar2' => ["Name" => 'myvar2', "Type" => "MyType", "Summary" => "some other doc\non another line\nand another\n",
  98. "Constraints" => [
  99. ["Method" => "min", "Arguments" => [42]],
  100. ["Method" => "max", "Arguments" => [42]],
  101. ["Method" => "between", "Arguments" => [0, 42]],
  102. ["Method" => "another", "Arguments" => [1, 2, 42.42, true, false, "a string", "string", null]]
  103. ]
  104. ]
  105. ];
  106. $this->assertSame($expectedParams, $params);
  107. }
  108. }