GetFromUrlParamTagTest.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Strategies\UrlParameters;
  3. use Knuckles\Scribe\Extracting\Strategies\UrlParameters\GetFromUrlParamTag;
  4. use Knuckles\Scribe\Tools\DocumentationConfig;
  5. use Mpociot\Reflection\DocBlock\Tag;
  6. use PHPUnit\Framework\TestCase;
  7. use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
  8. class GetFromUrlParamTagTest extends TestCase
  9. {
  10. use ArraySubsetAsserts;
  11. /** @test */
  12. public function can_fetch_from_urlparam_tag()
  13. {
  14. $strategy = new GetFromUrlParamTag(new DocumentationConfig([]));
  15. $tags = [
  16. new Tag('urlParam', 'id required The id of the order.'),
  17. new Tag('urlParam', 'lang The language to serve in.'),
  18. new Tag('urlParam', 'withType number With type, maybe.'),
  19. new Tag('urlParam', 'withTypeDefinitely integer required With type.'),
  20. new Tag('urlParam', 'barebones'),
  21. new Tag('urlParam', 'barebonesType number'),
  22. new Tag('urlParam', 'barebonesRequired required'),
  23. new Tag('urlParam', 'withExampleOnly Example: 12'),
  24. new Tag('urlParam', 'withExampleOnlyButTyped int Example: 12'),
  25. new Tag('urlParam', 'noExampleNoDescription No-example.'),
  26. new Tag('urlParam', 'noExample Something No-example'),
  27. ];
  28. $results = $strategy->getFromTags($tags);
  29. $this->assertArraySubset([
  30. 'id' => [
  31. 'type' => 'string',
  32. 'required' => true,
  33. 'description' => 'The id of the order.',
  34. ],
  35. 'lang' => [
  36. 'type' => 'string',
  37. 'required' => false,
  38. 'description' => 'The language to serve in.',
  39. ],
  40. 'withType' => [
  41. 'type' => 'number',
  42. 'required' => false,
  43. 'description' => 'With type, maybe.',
  44. ],
  45. 'withTypeDefinitely' => [
  46. 'type' => 'integer',
  47. 'required' => true,
  48. 'description' => 'With type.',
  49. ],
  50. 'barebones' => [
  51. 'type' => 'string',
  52. 'required' => false,
  53. 'description' => '',
  54. ],
  55. 'barebonesType' => [
  56. 'type' => 'number',
  57. 'required' => false,
  58. 'description' => '',
  59. ],
  60. 'barebonesRequired' => [
  61. 'type' => 'string',
  62. 'required' => true,
  63. 'description' => '',
  64. ],
  65. 'withExampleOnly' => [
  66. 'type' => 'string',
  67. 'required' => false,
  68. 'description' => '',
  69. 'example' => '12',
  70. ],
  71. 'withExampleOnlyButTyped' => [
  72. 'type' => 'integer',
  73. 'required' => false,
  74. 'description' => '',
  75. 'example' => 12
  76. ],
  77. 'noExampleNoDescription' => [
  78. 'type' => 'string',
  79. 'required' => false,
  80. 'description' => '',
  81. 'example' => null
  82. ],
  83. 'noExample' => [
  84. 'type' => 'string',
  85. 'required' => false,
  86. 'description' => 'Something',
  87. 'example' => null
  88. ],
  89. ], $results);
  90. }
  91. }