UseResponseTagTest.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Strategies\Responses;
  3. use Knuckles\Scribe\Extracting\Strategies\Responses\UseResponseTag;
  4. use Knuckles\Scribe\Tools\DocumentationConfig;
  5. use Mpociot\Reflection\DocBlock\Tag;
  6. use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
  7. use PHPUnit\Framework\TestCase;
  8. class UseResponseTagTest extends TestCase
  9. {
  10. use ArraySubsetAsserts;
  11. /**
  12. * @test
  13. * @dataProvider responseTags
  14. */
  15. public function allows_multiple_response_tags_for_multiple_statuses_and_scenarios(array $tags, array $expected)
  16. {
  17. $strategy = new UseResponseTag(new DocumentationConfig([]));
  18. $results = $strategy->getDocBlockResponses($tags);
  19. $this->assertEquals($expected[0]['status'], $results[0]['status']);
  20. $this->assertEquals($expected[1]['status'], $results[1]['status']);
  21. $this->assertEquals($expected[0]['description'], $results[0]['description']);
  22. $this->assertEquals($expected[1]['description'], $results[1]['description']);
  23. $this->assertEquals($expected[0]['content'], json_decode($results[0]['content'], true));
  24. $this->assertEquals($expected[1]['content'], json_decode($results[1]['content'], true));
  25. }
  26. public static function responseTags()
  27. {
  28. $response1 = '{
  29. "id": 4,
  30. "name": "banana"
  31. }';
  32. $response2 = '{
  33. "message": "Unauthorized"
  34. }';
  35. return [
  36. "with status as initial position" => [
  37. [
  38. new Tag('response', $response1),
  39. new Tag('response', "401 $response2"),
  40. ],
  41. [
  42. [
  43. 'status' => 200,
  44. 'description' => '',
  45. 'content' => [
  46. 'id' => 4,
  47. 'name' => 'banana',
  48. ],
  49. ],
  50. [
  51. 'status' => 401,
  52. 'description' => '',
  53. 'content' => [
  54. 'message' => 'Unauthorized',
  55. ],
  56. ],
  57. ],
  58. ],
  59. "with fields" => [
  60. [
  61. new Tag('response', "scenario=\"success\" $response1"),
  62. new Tag('response', "status=401 scenario='auth problem' $response2"),
  63. ],
  64. [
  65. [
  66. 'status' => 200,
  67. 'description' => 'success',
  68. 'content' => [
  69. 'id' => 4,
  70. 'name' => 'banana',
  71. ],
  72. ],
  73. [
  74. 'status' => 401,
  75. 'description' => 'auth problem',
  76. 'content' => [
  77. 'message' => 'Unauthorized',
  78. ],
  79. ],
  80. ],
  81. ],
  82. ];
  83. }
  84. }