Skip to content

Commit d50df91

Browse files
committed
test: Cover legacy behaviour of tag filter with no @ prefix
1 parent 05a7459 commit d50df91

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tests/Filter/TagFilterTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Behat\Gherkin\Node\OutlineNode;
1717
use Behat\Gherkin\Node\ScenarioNode;
1818
use ErrorException;
19+
use PHPUnit\Framework\Attributes\DataProvider;
1920
use PHPUnit\Framework\TestCase;
2021

2122
class TagFilterTest extends TestCase
@@ -278,6 +279,43 @@ public function testFilterFeatureWithTaggedExamples(): void
278279
$this->assertEquals([$exampleTableNode3], $scenarioInterfaces[1]->getExampleTables());
279280
}
280281

282+
/**
283+
* @phpstan-return list<array{string, list<string>, bool}>
284+
*/
285+
public static function provderMatchWithNoPrefixInFilter(): array
286+
{
287+
// This is officially unsupported (but potentially widespread) use of a filter expression that does not
288+
// contain the `@` prefix. Behat's documentation shows that the `@` prefix should be provided - however Behat's
289+
// own tests include an example where this is not the case, which has been passing. Gherkin has not historically
290+
// validated the tag expression, so we will continue to support these for now.
291+
// These cases rely on the bulk of the coverage being provided by the other tests, and the knowledge that the
292+
// implementation ultimately uses the same logic to compare tags from all types of nodes.
293+
// They are only intended to be temporary until we enforce that filter expressions are valid.
294+
return [
295+
['wip', [], false],
296+
['wip', ['slow'], false],
297+
['wip', ['wip'], true],
298+
['wip', ['slow', 'wip'], true],
299+
['tag1&&~tag2&&tag3', [], false],
300+
['tag1&&~tag2&&tag3', ['tag1'], false],
301+
['tag1&&~tag2&&tag3', ['tag1', 'tag3'], true],
302+
['tag1&&~tag2&&tag3', ['tag1', 'tag2'], false],
303+
['tag1&&~tag2&&tag3', ['tag1', 'tag4'], false],
304+
['tag1&&~tag2&&tag3', ['tag1', 'tag2', 'tag3'], false],
305+
];
306+
}
307+
308+
/**
309+
* @phpstan-param list<string> $tags
310+
*/
311+
#[DataProvider('provderMatchWithNoPrefixInFilter')]
312+
public function testItMatchesWhenFilterDoesNotContainPrefix(string $filter, array $tags, bool $expect): void
313+
{
314+
$feature = new FeatureNode(null, null, $tags, null, [], '', '', null, 1);
315+
$tagFilter = new TagFilter($filter);
316+
$this->assertSame($expect, $tagFilter->isFeatureMatch($feature));
317+
}
318+
281319
public function testFilterWithWhitespaceIsDeprecated(): void
282320
{
283321
$this->expectDeprecationError();

0 commit comments

Comments
 (0)