From dc2cf7a40f5e7002a02f59023b58dd776db8370a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Heitz?= Date: Mon, 28 Mar 2022 10:04:50 +0200 Subject: [PATCH] Codeception 5 compatibility (#66) * initial change for codecept5 * refactor changes * add Codeception 5.x to Requirements * fix compatibility issues Co-authored-by: Gregory Heitz --- Earthfile | 10 +++--- README.md | 10 +++--- codeception.dist.yml | 3 +- composer.json | 15 +++++--- src/GherkinParam.php | 54 +++++++++++++---------------- tests/_support/AcceptanceTester.php | 4 +-- tests/acceptance.suite.dist.yml | 2 +- tests/unit.suite.dist.yml | 2 +- 8 files changed, 52 insertions(+), 48 deletions(-) diff --git a/Earthfile b/Earthfile index 92f0eea..9a4b813 100644 --- a/Earthfile +++ b/Earthfile @@ -1,13 +1,15 @@ -ARG version=7.4 +ARG version=8.0 ARG vendor=./vendor/bin FROM php:$version-alpine WORKDIR /codeception ENV XDEBUG_MODE=coverage deps: + RUN apk add git libzip-dev zip RUN apk add --quiet --no-progress --no-cache $PHPIZE_DEPS RUN pecl -q install xdebug RUN docker-php-ext-enable xdebug + RUN docker-php-ext-install zip RUN curl -sS https://getcomposer.org/installer | \ php -- --install-dir=/usr/bin --filename=composer @@ -17,15 +19,15 @@ setup: RUN composer update \ --prefer-stable \ --no-progress \ - --no-interaction \ - --quiet + --no-interaction test: FROM +setup RUN $vendor/codecept run \ --no-interaction \ --coverage \ - --coverage-xml + --coverage-xml \ + -v SAVE ARTIFACT tests/_output AS LOCAL ./tests/_output mutation: diff --git a/README.md b/README.md index 9cd4aa3..1f30861 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ scenario. ## Minimum Requirements -- Codeception 3.x, 4.x +- Codeception 3.x, 4.x, 5.x - PHP 7.4 - 8.1 (use release 2.0.6 for older PHP versions) ## Installation @@ -80,20 +80,20 @@ modules: ## Usage Once installed you will be able to access variables stored using -[Fixtures](https://codeception.com/docs/reference/Fixtures.html). +[Fixtures](https://codeception.com/docs/reference/Fixtures.html). ### Simple parameters -In scenario steps, the variables can be accessed using the syntax `{{param}}`. +In scenario steps, the variables can be accessed using the syntax `{{param}}`. While executing your features the variables will be automatically replaced by their value. ### Array parameters -You can refer to an element in an array using the syntax `{{param[key]}}`. +You can refer to an element in an array using the syntax `{{param[key]}}`. ### Test Suite Config parameters -You can refer to a test suite configuration parameter using the syntax `{{config:param}}`. +You can refer to a test suite configuration parameter using the syntax `{{config:param}}`. Note that the keyword **config:** is mandatory. ## Example diff --git a/codeception.dist.yml b/codeception.dist.yml index 39ce7a0..db11f34 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -6,6 +6,7 @@ paths: data: tests/_data support: tests/_support envs: tests/_envs + output: tests/_output settings: colors: true @@ -29,4 +30,4 @@ coverage: modules: enabled: - - Codeception\Extension\GherkinParam \ No newline at end of file + - Codeception\Extension\GherkinParam diff --git a/composer.json b/composer.json index 64c33df..79642ee 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,14 @@ { "name": "edno/codeception-gherkin-param", "description": "Codeception module for supporting parameter notation in Gherkin features", - "keywords": ["codeception", "extension", "gherkin", "bdd", "module", "test"], + "keywords": [ + "codeception", + "extension", + "gherkin", + "bdd", + "module", + "test" + ], "homepage": "https://edno.github.io/codeception-gherkin-param", "license": "Apache-2.0", "authors": [ @@ -18,15 +25,15 @@ "require-dev": { "brainmaestro/composer-git-hooks": "^2.8", "codeception/assert-throws": "^1.2", - "codeception/module-asserts": "^2", - "codeception/mockery-module": "^0.4", + "codeception/module-asserts": "^2.0|^3.0", + "codeception/mockery-module": "^0.4|^0.5", "infection/codeception-adapter": "^0.4", "infection/infection": "^0.26", "php-coveralls/php-coveralls": "^2", "phpstan/phpstan": "^0.12", "phpstan/phpstan-deprecation-rules": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpmd/phpmd" : "@stable", + "phpmd/phpmd": "@stable", "squizlabs/php_codesniffer": "^3" }, "autoload": { diff --git a/src/GherkinParam.php b/src/GherkinParam.php index b4d403a..5133899 100644 --- a/src/GherkinParam.php +++ b/src/GherkinParam.php @@ -31,6 +31,7 @@ use \Codeception\Exception\ExtensionException; use \Codeception\Configuration; use \Codeception\Step; +use \Codeception\Lib\ModuleContainer; use \Codeception\Extension\GherkinParamException; /** @@ -39,15 +40,34 @@ * @category Test * @package GherkinParam * @author Gregory Heitz - * @license https://git.io/Juy0k Apache Licence + * @license https://git.io/Juy0k Apache License * @link https://packagist.org/packages/edno/codeception-gherkin-param * * @SuppressWarnings(PHPMD.CamelCaseMethodName) * @SuppressWarnings(PHPMD.CamelCaseVariableName) * @SuppressWarnings(PHPMD.CamelCasePropertyName) */ + class GherkinParam extends \Codeception\Module { + /** + * List events to listen to + * + * @var array + */ + public static array $events = [ + //run before any suite + 'suite.before' => 'beforeSuite', + //run before any steps + 'step.before' => 'beforeStep' + ]; + + /** + * Current test suite config + * + * @var array + */ + private static $_suiteConfig; /** * Flag to enable exception (prioritized over $_nullable=true) @@ -57,7 +77,7 @@ class GherkinParam extends \Codeception\Module * instead replacement value is parameter {{name}} * true: exception thrown if parameter invalid */ - private $_throwException = false; + private bool $_throwException = false; /** * Flag to null invalid parameter (incompatible with $_throwException=true) @@ -66,40 +86,14 @@ class GherkinParam extends \Codeception\Module * true: if parameter invalid then replacement value will be null * false: default behaviour, ie replacement value is parameter {{name}} */ - private $_nullable = false; - - /** - * Array of configuration parameters - * - * @var array - */ - protected $config = ['onErrorThrowException', 'onErrorNull']; - - /** - * List events to listen to - * - * @var array - */ - public static $events = [ - //run before any suite - 'suite.before' => 'beforeSuite', - //run before any steps - 'step.before' => 'beforeStep' - ]; - - /** - * Current test suite config - * - * @var array - */ - private static $_suiteConfig; + private bool $_nullable = false; /** * RegExp for parsing steps * * @var array */ - private static $_regEx = [ + private static array $_regEx = [ 'match' => '/{{\s?[A-z0-9_:-<>]+\s?}}/', 'filter' => '/[{}]/', 'config' => '/(?:^config)?:([A-z0-9_-]+)+(?=:|$)/', diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php index 2632206..4896d75 100644 --- a/tests/_support/AcceptanceTester.php +++ b/tests/_support/AcceptanceTester.php @@ -116,9 +116,9 @@ public function iSeeTableNull(TableNode $table): void */ public function theConfigurationParameterIsSetTo( string $param, - bool $value + ?string $value ): void { - $this->setConfigParam($param, $value); + $this->setConfigParam($param, (bool)$value); } } diff --git a/tests/acceptance.suite.dist.yml b/tests/acceptance.suite.dist.yml index 335576c..947be68 100644 --- a/tests/acceptance.suite.dist.yml +++ b/tests/acceptance.suite.dist.yml @@ -2,7 +2,7 @@ # # Suite for acceptance tests. -class_name: AcceptanceTester +actor: AcceptanceTester modules: enabled: diff --git a/tests/unit.suite.dist.yml b/tests/unit.suite.dist.yml index 9a2a451..e162429 100644 --- a/tests/unit.suite.dist.yml +++ b/tests/unit.suite.dist.yml @@ -2,7 +2,7 @@ # # Suite for unit tests. -class_name: UnitTester +actor: UnitTester modules: enabled: