Skip to content

Commit

Permalink
Merge pull request #4 from integratedexperts/master
Browse files Browse the repository at this point in the history
Major cleanup + tests.
  • Loading branch information
JordiGiros authored May 30, 2018
2 parents 6c76113 + baec92c commit a4eeb75
Show file tree
Hide file tree
Showing 24 changed files with 799 additions and 659 deletions.
42 changes: 42 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
version: 2
jobs:
build:
working_directory: /app
docker:
- image: integratedexperts/circleci2-builder
environment:
COMPOSER_ALLOW_SUPERUSER: 1
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Pull newest Docker images.
command: composer docker:pull
- run:
name: Start containers.
command: |
composer docker:start
- run:
name: Copy codebase into container.
command: |
docker cp -L /app/. $(docker-compose ps -q phpserver):/app/
- run:
name: Install dev dependencies.
command: |
composer docker:cli -- composer install --ansi
- run:
name: Lint code.
command: composer docker:cli -- composer lint
- run:
name: Run tests.
command: |
composer docker:cli -- mkdir -p /app/screenshots
composer docker:cli -- composer test
- run:
name: Copy artifacts.
command: |
mkdir -p /tmp/artifacts/behat
docker cp $(docker-compose ps -q phpserver):/app/screenshots /tmp/artifacts/behat
- store_artifacts:
path: /tmp/artifacts
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[composer.{json,lock}]
indent_size = 4

[phpcs.xml]
indent_size = 4

[phpunit.xml]
indent_size = 4
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vendor
composer.lock
screenshots
6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

181 changes: 72 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,157 +1,120 @@
# MinkFieldRandomizer
MinkFieldRandomizer is a random (with sense) information generator for filling browser form fields in Behat Mink Selenium tests. It brings the option to run your tests in a more realistic way changing the information you use to fill in the forms in every test you run.
# Behat Mink Field Randomizer
`MinkFieldRandomizer` is a random (with sense) information generator for filling form fields in Behat Mink tests.
It brings the option to run your tests in a more realistic way changing the information you use to fill in the forms
in every test you run.

Status: v1.0. Working.
Feel free to propose improvments.
[![CircleCI](https://circleci.com/gh/integratedexperts/MinkFieldRandomizer.svg?style=shield)](https://circleci.com/gh/integratedexperts/MinkFieldRandomizer)

## Add it using composer
Add the next line in require-dev to your composer.json file:
"jordigiros/MinkFieldRandomizer": "dev-master"
## Installing with Composer
```
composer require jordigiros/MinkFieldRandomizer
```

## How to use it
MinkFieldRandomizer includes a file called FilterContext.php that contains a PHP trait class. This class has some extra methods that will permit you to randomize your features involving forms.
## How to use
`MinkFieldRandomizer` includes a trait `FieldRandomizerTrait` that has some extra methods that will permit you to randomize your features involving forms.

You only need to add that trait to your main FeatureContext Behat Contaxt as follows:
You only need to add that trait to your main `FeatureContext` Behat Context as follows:

```javascript
class FeatureContext extends MinkContext implements Context, SnippetAcceptingContext
{
```
class FeatureContext extends MinkContext {
use FieldRandomizerTrait;
use FilterContext;

...
}
```

This way you can use the new steps added by the trait directly in the gherkin feature.

# Steps added By MinkFieldRandomizer
# Steps added by `MinkFieldRandomizer`

Documentation

### Common methods
## Common methods

#### Generate and fill with new random information
### Generate and fill with new random values

* Fill :field with a random mail
* Fill :field with a random name
* Fill :field with a random surname
* Fill :field with a random phone
* Fill :field with a random number
* Fill :field with a random text
* Fill :field with a random loremipsum
* When I fill in :field with a random mail
* When I fill in :field with a random name
* When I fill in :field with a random surname
* When I fill in :field with a random phone
* When I fill in :field with a random number
* When I fill in :field with a random text
* When I fill in :field with a random loremipsum

#### Fill in with previous generated random information
### Fill in with previously generated random values

* Fill :field with an existent mail
* Fill :field with an existent name
* Fill :field with an existent surname
* Fill :field with an existent phone
* Fill :field with an existent number
* Fill :field with an existent text
* Fill :field with an existent loremipsum
* When I fill in :field with an existent mail
* When I fill in :field with an existent name
* When I fill in :field with an existent surname
* When I fill in :field with an existent phone
* When I fill in :field with an existent number
* When I fill in :field with an existent text
* When I fill in :field with an existent loremipsum

Note: If you didn't generate the random information previously (Generate and fill with new random information) they won't work.

#### Other methods

##### Filling multiple fields with a TableNode object:
### Filling multiple fields with a TableNode object:

* Fills in form fields with provided table.

Gherkin:
```javascript
Then Fills in form fields with provided table
| "f_outbound_accommodation_name" | "{RandomName}" |
| "f_outbound_accommodation_phone_number" | "{RandomNumber}" |
| "f_outbound_accommodation_address_1" | "{RandomText(10)}" |
```
When I fill in fields with provided table:
| f_outbound_accommodation_name | {RandomName} |
| f_outbound_accommodation_phone_number | {RandomNumber} |
| f_outbound_accommodation_address_1 | {RandomText(10)} |
````
PHP:
```javascript
$hotel = new TableNode (
array(
array("f_outbound_accommodation_name", "{RandomName}"),
array("f_outbound_accommodation_phone_number", "{RandomNumber}"),
array("f_outbound_accommodation_address_1", "{RandomText(10)}")
)
);
```
$hotel = new TableNode ([
['f_outbound_accommodation_name', '{RandomName}'],
['f_outbound_accommodation_phone_number', '{RandomNumber}'],
['f_outbound_accommodation_address_1', '{RandomText(10)}'],
]);
$this->fillFilteredFields($hotel);
```
##### Checking that a field has an specific previous random generated information:

* /^the "(?P<field>(?:[^"]|\\")*)" field should contains "(?P<value>(?:[^"]|\\")*)" value$/
#### Checking that a field has an specific previous random generated information:
```javascript
$this->assertFieldContainsValue("f_customer_first_name", "name");
Gherkin:
```
Then the ":field" field should contains ":value" value
```
PHP:
```
$this->frtAssertFieldContainsValue('f_customer_first_name', 'name');
```
It will fail if field contains a value different than the one given.
##### Filling a field with a custom random value

* Fill :field with :value

```javascript
Then Fill "#text" with "{RandomText(100)}"
### Filling a field with a custom random value
Gherkin:
```
When I fill in :field with :value
```
PHP:
```
When I fill in "#text" with "{RandomText(100)}"
```
It brings the option to customize some properties of the random values.
# Values and customization
List of the posible values that can be used

#### Email
* {RandomEmail}

RandomEmail does not accept parameters

#### Name
* {RandomName}

RandomName does not accept parameters

#### Surname
* {RandomSurname}

RandomSurname does not accept parameters

#### Number
* {RandomNumber}

* {RandomNumber(N,M)}

RandomNumber accepts at most two parameters, returns a random number between the two given or between 0 and 9 if no params given.

#### Phone
* {RandomPhone}

* {RandomPhone(N)}

RandomPhone accepts at most a parameter, the number of numbers in the string.
If no parameter is given, it will return a 15 digits number.

#### Text
* {RandomText}

* {RandomText(N)}

RandomText accepts at most a parameter, the number of characters in the string.
If no parameter is given, it will return a 15 chars string.

#### LoremIpsum
* {RandomLoremIpsum}

* {RandomLoremIpsum(N)}

RandomLoremIpsum accepts at most a parameter, the number of paragraphs in the string.
If no parameter is given, it will return a 2 paragraphs string.
| Name | Value | Comment |
|---------------|---------------------------------------------------|---------------------------------------|
|`Email` |`{RandomEmail}` |RandomEmail does not accept parameters |
|`Name` |`{RandomName}` |RandomName does not accept parameters |
|`Surname` |`{RandomSurname}` |RandomSurname does not accept parameters|
|`Number` |`{RandomNumber}`<br/>`{RandomNumber(N,M)}` |RandomNumber accepts at most two parameters, returns a random number between the two given or between 0 and 9 if no params given.|
|`Phone` |`{RandomPhone}`<br/>`{RandomPhone(N)}` |RandomPhone accepts at most a parameter, the number of numbers in the string. If no parameter is given, it will return a 15 digits number.|
|`Text` |`{RandomText}`<br/>`{RandomText(N)}` |RandomText accepts at most a parameter, the number of characters in the string.If no parameter is given, it will return a 15 chars string.|
|`LoremIpsum` |`{RandomLoremIpsum}`<br/>`{RandomLoremIpsum(N)}` |RandomLoremIpsum accepts at most a parameter, the number of paragraphs in the string. If no parameter is given, it will return a 2 paragraphs string.|
# Copyright
Copyright (c) 2016 Jordi Girós Guerrero. See LICENSE for details.
Contributors: Jordi Bisbal.
Contributors: Jordi Bisbal, Alex Skrypnyk.
38 changes: 38 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
default:
autoload: [ "%paths.base%/tests/behat/bootstrap" ]
suites:
default:
paths: [ "%paths.base%/tests/behat/features" ]
contexts:
- IntegratedExperts\BehatPhpServer\PhpServerContext:
-
docroot: "%paths.base%/tests/behat/fixtures"
host: "phpserver"
- IntegratedExperts\BehatScreenshotExtension\Context\ScreenshotContext
- FeatureContext
extensions:
Behat\MinkExtension:
goutte: ~
files_path: "%paths.base%/tests/behat/fixtures"
browser_name: chrome
base_url: http://phpserver:8888
IntegratedExperts\BehatScreenshotExtension:
dir: "%paths.base%/screenshots"
fail: true
purge: true

# Run this on local machine (outside of the container):
# vendor/bin/behat -p local
local:
suites:
default:
contexts:
- IntegratedExperts\BehatPhpServer\PhpServerContext:
-
docroot: "%paths.base%/tests/behat/fixtures"
host: "localhost"
- IntegratedExperts\BehatScreenshotExtension\Context\ScreenshotContext
- FeatureContext
extensions:
Behat\MinkExtension:
base_url: http://localhost:8888
45 changes: 34 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,51 @@
{
"autoload": {
"psr-4": {
"MinkFieldRandomizer\\Filter\\": "src/MinkFieldRandomizer/Filter/",
"MinkFieldRandomizer\\Context\\": "src/MinkFieldRandomizer/Context/",
"MinkFieldRandomizer\\Model\\": "src/MinkFieldRandomizer/Model/",
"MinkFieldRandomizer\\Registry\\": "src/MinkFieldRandomizer/Registry/"
}
},
"name": "jordigiros/minkfieldrandomizer",
"description": "Random field filling generator for Behat/Mink/Selenium form tests",
"authors": [
{
"name": "jordigiros",
"email": "[email protected]"
},
{
"name": "Alex Skrypnyk",
"email": "[email protected]"
}
],
"minimum-stability": "dev",
"require": {
"behat/behat": "~3.0",
"behat/mink-extension": "~2.0",
"behat/mink-goutte-driver": "1.2.x",
"behat/mink-selenium2-driver": "1.3.x"
},
"config": {
"bin-dir": "bin"
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.4",
"jakub-onderka/php-parallel-lint": "^1.0",
"wimg/php-compatibility": "^8.1",
"escapestudios/symfony2-coding-standard": "^3.4",
"integratedexperts/behat-phpserver": "^0.1.1",
"integratedexperts/behat-screenshot": "^0.7.2"
},
"autoload": {
"psr-4": {
"MinkFieldRandomizer\\Filter\\": "src/MinkFieldRandomizer/Filter/",
"MinkFieldRandomizer\\Context\\": "src/MinkFieldRandomizer/Context/",
"MinkFieldRandomizer\\Model\\": "src/MinkFieldRandomizer/Model/",
"MinkFieldRandomizer\\Registry\\": "src/MinkFieldRandomizer/Registry/"
}
},
"scripts": {
"lint": [
"phpcs",
"parallel-lint --exclude vendor --exclude -e src tests"
],
"test": "behat --colors --format=progress",
"cleanup": "rm -Rf $(pwd)/vendor; rm composer.lock",
"docker:start": "docker-compose up -d --build",
"docker:restart": "docker-compose restart",
"docker:stop": "docker-compose stop",
"docker:destroy": "docker-compose down",
"docker:cli": "docker exec -i $(docker-compose ps -q phpserver)",
"docker:pull": "docker image ls --format \"{{.Repository}}:{{.Tag}}\" | grep amazeeio | grep -v none | xargs -n1 docker pull | cat",
"docker:logs": "docker-compose logs"
}
}
Loading

0 comments on commit a4eeb75

Please sign in to comment.