|
16 | 16 | use Behat\Gherkin\Node\OutlineNode; |
17 | 17 | use Behat\Gherkin\Node\ScenarioNode; |
18 | 18 | use ErrorException; |
| 19 | +use PHPUnit\Framework\Attributes\DataProvider; |
19 | 20 | use PHPUnit\Framework\TestCase; |
20 | 21 |
|
21 | 22 | class TagFilterTest extends TestCase |
@@ -278,6 +279,43 @@ public function testFilterFeatureWithTaggedExamples(): void |
278 | 279 | $this->assertEquals([$exampleTableNode3], $scenarioInterfaces[1]->getExampleTables()); |
279 | 280 | } |
280 | 281 |
|
| 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 | + |
281 | 319 | public function testFilterWithWhitespaceIsDeprecated(): void |
282 | 320 | { |
283 | 321 | $this->expectDeprecationError(); |
|
0 commit comments