Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of single line DocBlock #4693

Merged
merged 1 commit into from Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Metadata/Parser/Annotation/DocBlock.php
Expand Up @@ -130,8 +130,8 @@ public function requirements(): array
'__FILE' => realpath($this->fileName),
];

// Split docblock into lines and rewind offset to start of docblock
$lines = preg_split('/\r\n|\r|\n/', $this->docComment);
// Trim docblock markers, split it into lines and rewind offset to start of docblock
$lines = preg_replace(['#^/\*{2}#', '#\*/$#'], '', preg_split('/\r\n|\r|\n/', $this->docComment));
$offset -= count($lines);

foreach ($lines as $line) {
Expand Down
5 changes: 5 additions & 0 deletions tests/_files/Metadata/Annotation/tests/RequiresPhpTest.php
Expand Up @@ -22,4 +22,9 @@ final class RequiresPhpTest extends TestCase
public function testOne(): void
{
}

/** @requires PHP < 9.0.0 */
public function testTwo(): void
{
}
}
12 changes: 10 additions & 2 deletions tests/unit/Metadata/Parser/AnnotationParserTest.php
Expand Up @@ -587,9 +587,17 @@ public function test_Parses_requiresOperatingSystemFamily_annotation_on_method()
$this->assertSame('Linux', $metadata->asArray()[0]->operatingSystemFamily());
}

public function test_Parses_requiresPhp_annotation_on_method(): void
public function provideRequiresPhpTestMethods(): array
{
$metadata = (new AnnotationParser)->forMethod(RequiresPhpTest::class, 'testOne')->isRequiresPhp();
return [['testOne'], ['testTwo']];
}

/**
* @dataProvider provideRequiresPhpTestMethods
*/
public function test_Parses_requiresPhp_annotation_on_method(string $method): void
{
$metadata = (new AnnotationParser)->forMethod(RequiresPhpTest::class, $method)->isRequiresPhp();

$this->assertCount(1, $metadata);

Expand Down