Skip to content

Annotations in single-line doc-comments are not handled correctly #4692

@ostrolucky

Description

@ostrolucky
Q A
PHPUnit version master
PHP version any
Installation Method git

Summary

PHPUnit seems to require multiline docblocks for its annotations, eg. @requires. Some users prefer single line docblocks though and this is also now set in doctrine/coding-standard. We had this problem in https://github.com/doctrine/DoctrineBundle/pull/1365/files#diff-6c0dba5076ce8a2e9ff3e1e07f6661e095a18f80e32ad9766945f55c0414f8a2.

This seems to be because in your regexes you don't expect /** to be on same line as meat of the regex at

public const REGEX_DATA_PROVIDER = '/@dataProvider\s+([a-zA-Z0-9._:-\\\\x7f-\xff]+)/';
private const REGEX_REQUIRES_VERSION = '/@requires\s+(?P<name>PHP(?:Unit)?)\s+(?P<operator>[<>=!]{0,2})\s*(?P<version>[\d\.-]+(dev|(RC|alpha|beta)[\d\.])?)[ \t]*\r?$/m';
private const REGEX_REQUIRES_VERSION_CONSTRAINT = '/@requires\s+(?P<name>PHP(?:Unit)?)\s+(?P<constraint>[\d\t \-.|~^]+)[ \t]*\r?$/m';
private const REGEX_REQUIRES_OS = '/@requires\s+(?P<name>OS(?:FAMILY)?)\s+(?P<value>.+?)[ \t]*\r?$/m';
private const REGEX_REQUIRES_SETTING = '/@requires\s+(?P<name>setting)\s+(?P<setting>([^ ]+?))\s*(?P<value>[\w\.-]+[\w\.]?)?[ \t]*\r?$/m';
private const REGEX_REQUIRES = '/@requires\s+(?P<name>function|extension)\s+(?P<value>([^\s<>=!]+))\s*(?P<operator>[<>=!]{0,2})\s*(?P<version>[\d\.-]+[\d\.]?)?[ \t]*\r?$/m';
private const REGEX_TEST_WITH = '/@testWith\s+/';
private const REGEX_EXPECTED_EXCEPTION = '(@expectedException\s+([:.\w\\\\x7f-\xff]+)(?:[\t ]+(\S*))?(?:[\t ]+(\S*))?\s*$)m';

How to reproduce

/** @requires PHP 8 */
public function test(): void
{
}

Doesn't have any effect. Test case is not skipped on PHP < 8.

But with

/**
 * @requires PHP 8
 */
public function test(): void
{
}

It works.

Expected behavior

Both examples should work the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature/metadataIssues related to attributes and annotationstype/bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions