Skip to content
This repository has been archived by the owner on Jul 3, 2023. It is now read-only.

Commit

Permalink
Codeception 5 compatibility (#66)
Browse files Browse the repository at this point in the history
* initial change for codecept5

* refactor changes

* add Codeception 5.x to Requirements

* fix compatibility issues

Co-authored-by: Gregory Heitz <edno@users.noreply.github.com>
  • Loading branch information
edno and edno authored Mar 28, 2022
1 parent 7669ab7 commit dc2cf7a
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 48 deletions.
10 changes: 6 additions & 4 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ paths:
data: tests/_data
support: tests/_support
envs: tests/_envs
output: tests/_output

settings:
colors: true
Expand All @@ -29,4 +30,4 @@ coverage:

modules:
enabled:
- Codeception\Extension\GherkinParam
- Codeception\Extension\GherkinParam
15 changes: 11 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand Down
54 changes: 24 additions & 30 deletions src/GherkinParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use \Codeception\Exception\ExtensionException;
use \Codeception\Configuration;
use \Codeception\Step;
use \Codeception\Lib\ModuleContainer;
use \Codeception\Extension\GherkinParamException;

/**
Expand All @@ -39,15 +40,34 @@
* @category Test
* @package GherkinParam
* @author Gregory Heitz <edno@edno.io>
* @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<string,string>
*/
public static array $events = [
//run before any suite
'suite.before' => 'beforeSuite',
//run before any steps
'step.before' => 'beforeStep'
];

/**
* Current test suite config
*
* @var array<mixed>
*/
private static $_suiteConfig;

/**
* Flag to enable exception (prioritized over $_nullable=true)
Expand All @@ -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)
Expand All @@ -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<string>
*/
protected $config = ['onErrorThrowException', 'onErrorNull'];

/**
* List events to listen to
*
* @var array<string,string>
*/
public static $events = [
//run before any suite
'suite.before' => 'beforeSuite',
//run before any steps
'step.before' => 'beforeStep'
];

/**
* Current test suite config
*
* @var array<mixed>
*/
private static $_suiteConfig;
private bool $_nullable = false;

/**
* RegExp for parsing steps
*
* @var array<string,string>
*/
private static $_regEx = [
private static array $_regEx = [
'match' => '/{{\s?[A-z0-9_:-<>]+\s?}}/',
'filter' => '/[{}]/',
'config' => '/(?:^config)?:([A-z0-9_-]+)+(?=:|$)/',
Expand Down
4 changes: 2 additions & 2 deletions tests/_support/AcceptanceTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
2 changes: 1 addition & 1 deletion tests/acceptance.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Suite for acceptance tests.

class_name: AcceptanceTester
actor: AcceptanceTester

modules:
enabled:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit.suite.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Suite for unit tests.

class_name: UnitTester
actor: UnitTester

modules:
enabled:
Expand Down

0 comments on commit dc2cf7a

Please sign in to comment.