Skip to content

Commit

Permalink
Change error to deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranmcnulty committed Feb 10, 2021
1 parent 71ed1bd commit 1293188
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
Expand Down
7 changes: 7 additions & 0 deletions src/Behat/Gherkin/Filter/TagFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class TagFilter extends ComplexFilter
public function __construct($filterString)
{
$this->filterString = trim($filterString);

if(preg_match('/\s/u', $this->filterString)) {
trigger_error(
"Tags with whitespace are deprecated and may be removed in a future version",
E_USER_DEPRECATED
);
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions src/Behat/Gherkin/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,7 @@ protected function scanTags()
if(preg_match('/^(?<line>.*)\s+#.*$/', $line, $matches)) {
['line' => $line] = $matches;
$this->consumeLineUntil(mb_strlen($line, 'utf-8'));
}
else {
} else {
$this->consumeLine();
}

Expand Down
8 changes: 1 addition & 7 deletions src/Behat/Gherkin/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,13 +647,7 @@ protected function guardTags(array $tags)
{
foreach ($tags as $tag) {
if (preg_match('/\s/', $tag)) {
throw new ParserException(
sprintf(
"Invalid tag %s%s",
$tag,
$this->file ? 'in file ' . $this->file : ''
)
);
trigger_error('Whitespace in tags is deprecated, found "$tag"', E_USER_DEPRECATED);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion tests/Behat/Gherkin/Cucumber/CompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class CompatibilityTest extends TestCase
'invalid_language.feature' => 'Invalid language is silently ignored',
];

private $deprecatedInsteadOfParseError = [
'whitespace_in_tags.feature' => '/Whitespace in tags is deprecated/',
];

/**
* @var Parser
*/
Expand Down Expand Up @@ -95,7 +99,12 @@ public function testBadFeaturesDoNotParse(\SplFileInfo $file)
$this->markTestIncomplete($this->parsedButShouldNotBe[$file->getFilename()]);
}

$this->expectException(ParserException::class);
if (isset($this->deprecatedInsteadOfParseError[$file->getFilename()])) {
$this->expectDeprecation();
$this->expectDeprecationMessageMatches($this->deprecatedInsteadOfParseError[$file->getFilename()]);
} else {
$this->expectException(ParserException::class);
}
$gherkinFile = $file->getPathname();
$feature = $this->parser->parse(file_get_contents($gherkinFile), $gherkinFile);
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Behat/Gherkin/Filter/TagFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,4 +268,16 @@ public function testFilterFeatureWithTaggedExamples()
/** @noinspection PhpUndefinedMethodInspection */
$this->assertEquals(array($exampleTableNode3), $scenarioInterfaces[1]->getExampleTables());
}

public function testFilterWithWhitespaceIsDeprecated()
{
$this->expectDeprecation();
$tagFilter = new TagFilter('@tag with space');
$scenario = new ScenarioNode(null, ['tag with space'], array(), null, 2);
$feature = new FeatureNode(null, null, [], null, [$scenario], null, null, null, 1);

$scenarios = $tagFilter->filterFeature($feature)->getScenarios();

$this->assertEquals([$scenario], $scenarios);
}
}

0 comments on commit 1293188

Please sign in to comment.