AnnotationParserTest.php 1.7 KB

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