From 2790be693817e43f9ed8aea4140ee091f364a1e4 Mon Sep 17 00:00:00 2001 From: javer Date: Sat, 11 Sep 2021 22:05:57 +0300 Subject: [PATCH] Add PHP 8.1 support --- .github/workflows/build.yml | 2 +- src/Behat/Gherkin/Filter/NameFilter.php | 8 ++++++++ src/Behat/Gherkin/Filter/NarrativeFilter.php | 2 +- src/Behat/Gherkin/Filter/RoleFilter.php | 2 +- src/Behat/Gherkin/Lexer.php | 2 +- src/Behat/Gherkin/Node/TableNode.php | 2 ++ src/Behat/Gherkin/Parser.php | 10 +++++----- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f732a949..93d5d1d1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.2, 7.3, 7.4, 8.0] + php: [7.2, 7.3, 7.4, 8.0, 8.1] composer-flags: [ "" ] symfony-version: [ "" ] include: diff --git a/src/Behat/Gherkin/Filter/NameFilter.php b/src/Behat/Gherkin/Filter/NameFilter.php index dc6718d5..80974d1f 100644 --- a/src/Behat/Gherkin/Filter/NameFilter.php +++ b/src/Behat/Gherkin/Filter/NameFilter.php @@ -41,6 +41,10 @@ public function __construct($filterString) */ public function isFeatureMatch(FeatureNode $feature) { + if (null === $feature->getTitle()) { + return false; + } + if ('/' === $this->filterString[0]) { return 1 === preg_match($this->filterString, $feature->getTitle()); } @@ -57,6 +61,10 @@ public function isFeatureMatch(FeatureNode $feature) */ public function isScenarioMatch(ScenarioInterface $scenario) { + if (null === $scenario->getTitle()) { + return false; + } + if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) { return true; } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) { diff --git a/src/Behat/Gherkin/Filter/NarrativeFilter.php b/src/Behat/Gherkin/Filter/NarrativeFilter.php index 8982b388..eb5ae48d 100644 --- a/src/Behat/Gherkin/Filter/NarrativeFilter.php +++ b/src/Behat/Gherkin/Filter/NarrativeFilter.php @@ -44,7 +44,7 @@ public function __construct($regex) */ public function isFeatureMatch(FeatureNode $feature) { - return 1 === preg_match($this->regex, $feature->getDescription()); + return 1 === preg_match($this->regex, $feature->getDescription() ?? ''); } /** diff --git a/src/Behat/Gherkin/Filter/RoleFilter.php b/src/Behat/Gherkin/Filter/RoleFilter.php index 61fc74e5..0ad3a29a 100644 --- a/src/Behat/Gherkin/Filter/RoleFilter.php +++ b/src/Behat/Gherkin/Filter/RoleFilter.php @@ -46,7 +46,7 @@ public function __construct($role) */ public function isFeatureMatch(FeatureNode $feature) { - return 1 === preg_match($this->pattern, $feature->getDescription()); + return 1 === preg_match($this->pattern, $feature->getDescription() ?? ''); } /** diff --git a/src/Behat/Gherkin/Lexer.php b/src/Behat/Gherkin/Lexer.php index d1b7b272..1f3b3c40 100644 --- a/src/Behat/Gherkin/Lexer.php +++ b/src/Behat/Gherkin/Lexer.php @@ -483,7 +483,7 @@ protected function scanPyStringContent() $token = $this->scanText(); // swallow trailing spaces - $token['value'] = preg_replace('/^\s{0,' . $this->pyStringSwallow . '}/u', '', $token['value']); + $token['value'] = preg_replace('/^\s{0,' . $this->pyStringSwallow . '}/u', '', $token['value'] ?? ''); return $token; } diff --git a/src/Behat/Gherkin/Node/TableNode.php b/src/Behat/Gherkin/Node/TableNode.php index dacc7590..4099f640 100644 --- a/src/Behat/Gherkin/Node/TableNode.php +++ b/src/Behat/Gherkin/Node/TableNode.php @@ -14,6 +14,7 @@ use Behat\Gherkin\Exception\NodeException; use Iterator; use IteratorAggregate; +use ReturnTypeWillChange; /** * Represents Gherkin Table argument. @@ -333,6 +334,7 @@ public function __toString() * * @return Iterator */ + #[ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->getHash()); diff --git a/src/Behat/Gherkin/Parser.php b/src/Behat/Gherkin/Parser.php index 646b47f6..cdfe4450 100644 --- a/src/Behat/Gherkin/Parser.php +++ b/src/Behat/Gherkin/Parser.php @@ -235,7 +235,7 @@ protected function parseFeature() { $token = $this->expectTokenType('Feature'); - $title = trim($token['value']) ?: null; + $title = trim($token['value'] ?? ''); $description = null; $tags = $this->popTags(); $background = null; @@ -288,7 +288,7 @@ protected function parseFeature() return new FeatureNode( rtrim($title) ?: null, - rtrim($description) ?: null, + rtrim($description ?? '') ?: null, $tags, $background, $scenarios, @@ -310,7 +310,7 @@ protected function parseBackground() { $token = $this->expectTokenType('Background'); - $title = trim($token['value']); + $title = trim($token['value'] ?? ''); $keyword = $token['keyword']; $line = $token['line']; @@ -375,7 +375,7 @@ protected function parseScenario() { $token = $this->expectTokenType('Scenario'); - $title = trim($token['value']); + $title = trim($token['value'] ?? ''); $tags = $this->popTags(); $keyword = $token['keyword']; $line = $token['line']; @@ -436,7 +436,7 @@ protected function parseOutline() { $token = $this->expectTokenType('Outline'); - $title = trim($token['value']); + $title = trim($token['value'] ?? ''); $tags = $this->popTags(); $keyword = $token['keyword'];