1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace Knuckles\Scribe\Tools;
- use PHPUnit\Framework\TestCase;
- class AnnotationParserTest extends TestCase
- {
- /**
- * @test
- * @dataProvider annotations
- */
- public function can_parse_annotation_into_content_and_attributes(string $annotation, array $expected)
- {
- $result = AnnotationParser::parseIntoContentAndAttributes($annotation, ['status', 'scenario']);
- $this->assertEquals($expected, $result);
- }
- public function annotations()
- {
- return [
- "when attributes come first" => [
- 'status=400 scenario="things go wrong" {"message": "failed"}',
- [
- 'attributes' => ['status' => '400', 'scenario' => 'things go wrong'],
- 'content' => '{"message": "failed"}',
- ],
- ],
- "when attributes come last" => [
- '{"message": "failed"} status=400 scenario="things go wrong"',
- [
- 'attributes' => ['status' => '400', 'scenario' => 'things go wrong'],
- 'content' => '{"message": "failed"}',
- ],
- ],
- "when there are no attributes" => [
- '{"message": "failed"} ',
- [
- 'attributes' => ['status' => null, 'scenario' => null],
- 'content' => '{"message": "failed"}',
- ],
- ],
- "when there are some attributes" => [
- ' status=hey {"message": "failed"} ',
- [
- 'attributes' => ['status' => 'hey', 'scenario' => null],
- 'content' => '{"message": "failed"}',
- ],
- ],
- ];
- }
- }
|