AnnotationParserTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Knuckles\Scribe\Tests\Unit;
  3. use Knuckles\Scribe\Tools\AnnotationParser;
  4. use PHPUnit\Framework\TestCase;
  5. class AnnotationParserTest extends TestCase
  6. {
  7. /**
  8. * @test
  9. * @dataProvider annotations
  10. */
  11. public function can_parse_annotation_into_content_and_attributes(string $annotation, array $expected)
  12. {
  13. $result = AnnotationParser::parseIntoContentAndAttributes($annotation, ['status', 'scenario']);
  14. $this->assertEquals($expected, $result);
  15. }
  16. public function annotations()
  17. {
  18. return [
  19. "when attributes come first" => [
  20. 'status=400 scenario="things go wrong" {"message": "failed"}',
  21. [
  22. 'attributes' => ['status' => '400', 'scenario' => 'things go wrong'],
  23. 'content' => '{"message": "failed"}',
  24. ],
  25. ],
  26. "when attributes come last" => [
  27. '{"message": "failed"} status=400 scenario="things go wrong"',
  28. [
  29. 'attributes' => ['status' => '400', 'scenario' => 'things go wrong'],
  30. 'content' => '{"message": "failed"}',
  31. ],
  32. ],
  33. "when there are no attributes" => [
  34. '{"message": "failed"} ',
  35. [
  36. 'attributes' => ['status' => null, 'scenario' => null],
  37. 'content' => '{"message": "failed"}',
  38. ],
  39. ],
  40. "when there are some attributes" => [
  41. ' status=hey {"message": "failed"} ',
  42. [
  43. 'attributes' => ['status' => 'hey', 'scenario' => null],
  44. 'content' => '{"message": "failed"}',
  45. ],
  46. ],
  47. ];
  48. }
  49. }