Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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. }