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

2.0 - Support for handling invalid parameters (#23) #26

Merged
merged 19 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ branches:
- master

php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
Expand All @@ -15,7 +13,8 @@ before_script:
- composer install

script:
- ./vendor/bin/codecept run --coverage-xml
- "./vendor/bin/codecept run -o 'settings: shuffle: true' -q --no-colors --coverage-xml"
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.4" ]]; then ./vendor/bin/infection --min-covered-msi=70 --threads=4 --no-progress --log-verbosity="none"; fi

after_script:
- ./vendor/bin/php-coveralls
56 changes: 49 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ scenario.
- PHP 7.x

## Installation

The extension can be installed using [Composer](https://getcomposer.org)

```bash
Expand All @@ -26,32 +27,71 @@ $ composer require edno/codeception-gherkin-param --dev

Be sure to enable the extension in `codeception.yml` as shown in
[configuration](#configuration) below.
## Configuration

## Setup

Enabling **Gherkin Param** is done in `codeception.yml`.

```yaml
extensions:
modules:
enabled:
- Codeception\Extension\GherkinParam
```

> From version 2.0, **GherkinParam** is now a **module**.
> If you are upgrading from 1.x to 2.x, then you'll have to update your Codeception configuration.

## Configuration

The version 2.x introduces two configuration parameters for customizing runtime behaviour when the scenario parameters are invalid or not initialized (see #23 and #26).

> By default **GherkinParam** behaviour is to keep the parameter string unchanged when the replacement value for a parameter cannot be found, ie the parameter does not exist or is not accessible.

### `onErrorThrowException`

If `true` then GherkinParam will throw a exception `GherkinParam` at runtime when a replacement value cannot be found for a parameter:

```yaml
modules:
enabled:
- Codeception\Extension\GherkinParam
onErrorThrowException: true
```

> If `onErrorThrowException` is set then it will override `onErrorNullable`.

### `onErrorNullable`

If `true` then GherkinParam will set to `null` parameters for which a replacement value cannot be found:

```yaml
modules:
enabled:
- Codeception\Extension\GherkinParam
onErrorNullable: true
```

## Usage

Once installed you will be able to access variables stored using
[Fixtures](http://codeception.com/docs/reference/Fixtures).

### Simple parameters

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
From version 0.3, you can refer to an element in an array using the syntax `{{param[key]}}`.
If the key does not exist, then `null` is returned.

You can refer to an element in an array using the syntax `{{param[key]}}`.

### Test Suite Config parameters
From version 0.3, you can refer to a test suite configuration parameter using the syntax `{{config:param}}`.
Note that the keyword **config:** is mandatory. If the config parameter does not exists, then `null` is returned.

You can refer to a test suite configuration parameter using the syntax `{{config:param}}`.
Note that the keyword **config:** is mandatory.

## Example

```gherkin
Feature: Parametrize Gherkin Feature
In order to create dynamic Gherkin scenario
Expand All @@ -76,6 +116,7 @@ Feature: Parametrize Gherkin Feature
```

The steps definition in `AcceptanceTester.php` do not require any change

```php
/**
* @Given I have a parameter :param with value :value
Expand All @@ -93,8 +134,9 @@ The steps definition in `AcceptanceTester.php` do not require any change
$this->assertEquals($arg1, $arg2);
}
```
You can find more examples in the [test folder](https://github.com/edno/codeception-gherkin-param/tree/master/tests/acceptance).

You can find more examples in the [test folder](https://github.com/edno/codeception-gherkin-param/tree/master/tests/acceptance).

## License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fedno%2Fcodeception-gherkin-param.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fedno%2Fcodeception-gherkin-param?ref=badge_large)
4 changes: 2 additions & 2 deletions codeception.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ coverage:
include:
- src/*

extensions:
modules:
enabled:
- Codeception\Extension\GherkinParam
- Codeception\Extension\GherkinParam
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
},
"require-dev": {
"php-coveralls/php-coveralls": "^2",
"codeception/module-asserts": "^1"
"codeception/module-asserts": "^1",
"infection/infection": "^0.15"
},
"autoload": {
"psr-4": {
"Codeception\\Extension\\": "src/"
"Codeception\\Extension\\": "src/"
}
},
"minimum-stability": "dev",
Expand Down
22 changes: 22 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "tests/_output/infection/infection.log",
"summary": "tests/_output/infection/summary.log",
"perMutator": "tests/_output/infection/per-mutator.md",
"badge": {
"branch": "master"
}
},
"tmpDir": "tests/_output/tmp",
"mutators": {
"@default": true,
"@function_signature": false
},
"testFramework": "codeception"
}
Loading