Skip to content

Commit

Permalink
feat(driver): additional client
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone committed Apr 28, 2020
1 parent ab1909a commit d1d1bec
Show file tree
Hide file tree
Showing 20 changed files with 652 additions and 46 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: PantherExtension CI - Config
on: [ push, pull_request ]
jobs:
panther_extension:
name: Configuration
# https://hub.docker.com/_/ubuntu/
runs-on: ubuntu-18.04
steps:
# https://github.com/actions/checkout (official)
- name: Checkout
uses: actions/checkout@v2

# https://github.com/azohra/shell-linter (community)
- name: Lint check
uses: azohra/[email protected]
with:
path: "docker/php"
59 changes: 59 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PantherExtension CI
on: [ pull_request ]
jobs:
panther_extension:
name: PHP ${{ matrix.php-versions }}
# https://hub.docker.com/_/ubuntu/
runs-on: ubuntu-18.04
strategy:
fail-fast: true
matrix:
php-versions: ['7.1', '7.2', '7.3', '7.4']
steps:
# https://github.com/actions/checkout (official)
- name: Checkout
uses: actions/checkout@v2

# https://github.com/shivammathur/setup-php (community)
- name: Setup PHP, extensions and composer with shivammathur/setup-php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: zip, xdebug
coverage: xdebug
env:
update: true

# —— Composer️ —————————————————————————————————————————————————————————
- name: Validate composer.json and composer.lock
run: composer validate

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install

# —— Style —————————————————————————————————————————————————————————
- name: Launch PHP-CS-FIXER - src
run: php vendor/bin/php-cs-fixer fix --dry-run src

# —— Style —————————————————————————————————————————————————————————
- name: Launch PHP-CS-FIXER - tests
run: php vendor/bin/php-cs-fixer fix --dry-run tests

# —— PHPUnit —————————————————————————————————————————————————————————
- name: Launch PHPUnit tests
run: php vendor/bin/phpunit tests

# —— Infection —————————————————————————————————————————————————————————
- name: Launch Infection analysis
run: php vendor/bin/infection
14 changes: 11 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: PantherExtension CI
on: [ push, pull_request ]
on:
push:
branches:
- master
jobs:
panther_extension:
name: PHP ${{ matrix.php-versions }}
Expand All @@ -8,7 +11,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['7.1', '7.2', '7.3', '7.4']
steps:
# https://github.com/actions/checkout (official)
- name: Checkout
Expand All @@ -19,7 +22,8 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: zip
extensions: zip, xdebug
coverage: xdebug
env:
update: true

Expand Down Expand Up @@ -52,3 +56,7 @@ jobs:
# —— PHPUnit —————————————————————————————————————————————————————————
- name: Launch PHPUnit tests
run: php vendor/bin/phpunit tests

# —— Infection —————————————————————————————————————————————————————————
- name: Launch Infection analysis
run: php vendor/bin/infection
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ docker-compose.override.yml

# Style
.php_cs.cache

# Infection
infection.log
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DOCKER_COMPOSE = @docker-compose
PHP = $(DOCKER_COMPOSE) run --rm php

.DEFAULT_GOAL := help
.PHONY: boot down vendor tests
.PHONY: boot up down vendor tests

help:
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
Expand All @@ -13,10 +13,13 @@ help:
##---------------------------------------------------------------------------

boot: ## Launch the project
boot:
boot: up vendor

up: ## Up the containers
up:
$(DOCKER_COMPOSE) up -d --remove-orphans

down: ## Down the project
down: ## Down the containers
down:
$(DOCKER_COMPOSE) down

Expand All @@ -28,7 +31,7 @@ vendor:
## Tools
##---------------------------------------------------------------------------

php-cs-fixer: ## Run PHP-CS-FIXER against a specific directory
php-cs-fixer: ## Run PHP-CS-FIXER against a specific DIRECTORY
php-cs-fixer:
$(PHP) vendor/bin/php-cs-fixer fix $(DIRECTORY)

Expand All @@ -39,3 +42,7 @@ php-cs-fixer:
tests: ## Launch the PHPUnit tests
tests:
$(PHP) vendor/bin/phpunit tests

infection: ## Launch Infection
infection:
$(PHP) vendor/bin/infection
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,27 @@ default:
driver: 'chrome' # Or 'firefox', 'selenium', 'chrome' is the default value
```
If you need to use `Selenium`, just adapt the session configuration:

```yaml
# ...
extensions:
PantherExtension\Extension\PantherExtension: ~
Behat\MinkExtension:
browser_name: chrome
base_url: http://localhost
sessions:
default:
panther:
driver: 'selenium'
selenium:
hub_url: 'http://127.0.0.1:4444/wd/hub'
```

Here's a simple example using a POC project which call [API-Platform website](https://api-platform.com/)

```bash
```gherkin
Feature:
As a newbie in API-Platform, I want to document myself in many features
Expand All @@ -58,31 +76,43 @@ Feature:
Then I should be on "/docs/distribution/#adding-graphql-support" # FeatureContext::assertPageAddress()
Then I should see "You now have a GraphQL API!" # FeatureContext::assertPageContainsText()
Scenario: I should be able to document myself about GraphQL support # features/demo.feature:20
Given I am on "/" # FeatureContext::visit()
When I fill in "SEARCH..." with "GraphQL" # FeatureContext::fillField()
And I follow "Get started" # FeatureContext::clickLink()
When I follow "Adding GraphQL Support" # FeatureContext::clickLink()
Then I should be on "/docs/distribution/#adding-graphql-support" # FeatureContext::assertPageAddress()
Then I should see "You now have a GraphQL API!" # FeatureContext::assertPageContainsText()
And I wait for ".support" # PantherExtension\Context\PantherContext::iWaitForElement()
The desired element cannot be found in the given timeout or seems to appear later than expected. (PantherExtension\Driver\Exception\LogicException)
Scenario: I should be able to document myself about GraphQL support thanks to the search field # features/demo.feature:20
Given I am on "/" # FeatureContext::visit()
When I fill in "SEARCH..." with "GraphQL" # FeatureContext::fillField()
And I wait for "#algolia-autocomplete-listbox-0" # PantherExtension\Context\PantherContext::iWaitForElement()
Then I should see "Documentation" # FeatureContext::assertPageContainsText()
And I should see "Search by" # FeatureContext::assertPageContainsText()
And I should see "Enabling GraphQL" # FeatureContext::assertPageContainsText()
Scenario: I should be able to test the demo # features/demo.feature:29
Scenario: I should be able to test the demo # features/demo.feature:28
Given I am on "/" # FeatureContext::visit()
And I follow "Demo" # FeatureContext::clickLink()
Then I should be on "https://demo-client.api-platform.com/" # FeatureContext::assertPageAddress()
When I follow "API" # FeatureContext::clickLink()
Then I should be on "https://demo.api-platform.com/" # FeatureContext::assertPageAddress()
--- Failed scenarios:
Scenario: I should be able to test the demo # features/demo.feature:35
Given I am on "/" # FeatureContext::visit()
And I follow "Community" # FeatureContext::clickLink()
And I create a new client "test" using the "chrome" driver # PantherExtension\Context\PantherContext::iCreateANewClient()
Then I switch to client "test" # PantherExtension\Context\PantherContext::iSwitchToANewClient()
And I go to "/" # FeatureContext::visit()
Then I should see "REST and GraphQL framework to build modern API-driven projects" # FeatureContext::assertPageContainsText()
Then I remove the client "test" # PantherExtension\Context\PantherContext::iRemoveTheClient()
Then I should see "API Platform's community" # FeatureContext::assertPageContainsText()
6 scenarios (6 passed)
29 steps (29 passed)
0m28.61s (20.63Mb)
```

features/demo.feature:20
## Documentation

5 scenarios (4 passed, 1 failed)
22 steps (21 passed, 1 failed)
0m56.28s (20.56Mb)
```
The full documentation can be found [here](/doc)

## CI usage

Please refer to [Symfony Panther](https://github.com/symfony/panther) documentation about using it in CI environments.

## Development

Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
"behat/behat": "^3.0.5",
"behat/mink": "^1.5",
"behat/mink-extension": "^2.0",
"symfony/config": "^2.7|^3.0|^4.0",
"symfony/panther": "0.7.1"
"symfony/config": "^2.7|^3.0|^4.0|^5.0",
"symfony/panther": "^0.7.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "^8.5"
"infection/infection": "^0.13.6",
"phpunit/phpunit": "^7.5",
"friendsofphp/php-cs-fixer": "^2.16"
},
"autoload": {
"psr-4": {
"PantherExtension\\": "src/",
"PantherExtension\\Context\\": "src/Context/",
"PantherExtension\\Driver\\": "src/Driver/",
"PantherExtension\\Driver\\Element\\": "src/Driver/Element/",
"PantherExtension\\Driver\\Exception\\": "src/Driver/Exception/",
"PantherExtension\\Extension\\": "src/Extension/"
}
Expand Down
1 change: 1 addition & 0 deletions doc/ajax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Ajax
28 changes: 28 additions & 0 deletions doc/client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Client

[Symfony Panther](https://github.com/symfony/panther) provide a default client which is capable of using Chrome, Firefox and Selenium.
This extension aim to provide the same features (even if some may be missing for now), here's a list
of what's provided:

- Additional client

[Symfony Panther](https://github.com/symfony/panther) provides a shortcut which helps you to handle real-time features ([Mercure](https://mercure.rocks/), Websockets, etc),
this extension provide the same feature with the Gherkin approach:

```gherkin
Scenario: I should be able to test the real-time comments
Given I am on "/"
And I follow "Blog"
And I create a new client "test" using the "chrome" driver
Then I should have 2 clients
When I switch to client "test"
And I fill in "comment" with "new random comment"
And I press "Submit"
And I wait for ".comments" during 5
Then I should see 2 comments
And I switch to default client
Then I should see 2 comments
```

During this scenario, the extension will create a new client and let you switch to it if needed.
Once the scenario is done, the clients are automatically reset and you can continue to use the "default" client.
8 changes: 8 additions & 0 deletions docker-compose.override.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3.7'

services:
blackfire:
image: blackfire/blackfire
environment:
BLACKFIRE_SERVER_ID: 'test'
BLACKFIRE_SERVER_TOKEN: 'test'
19 changes: 18 additions & 1 deletion docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:7.2.22-cli
FROM php:7.1.33-cli

ENV APP_DIR=/srv/app \
BUILD_SCRIPTS_DIR=/build-scripts
Expand All @@ -11,7 +11,11 @@ RUN apt-get update \
libzip-dev=1.5.* \
wget=1.20.1-1.1 \
gpg=2.2.* \
zlib1g-dev=1:1.2.* \
chromium=80.0.* \
&& pecl install xdebug \
&& docker-php-ext-install opcache zip \
&& docker-php-ext-enable xdebug opcache zip \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand All @@ -27,6 +31,19 @@ COPY launcher.sh /usr/local/bin/launcher
RUN chmod +x /usr/local/bin/launcher
ENTRYPOINT ["launcher"]

# Blackfire {@see https://blackfire.io/docs/integrations/docker/php-docker}
RUN version=$(php -r "echo PHP_MAJOR_VERSION.PHP_MINOR_VERSION;") \
&& curl -A "Docker" -o /tmp/blackfire-probe.tar.gz -D - -L -s https://blackfire.io/api/v1/releases/probe/php/linux/amd64/$version \
&& mkdir -p /tmp/blackfire \
&& tar zxpf /tmp/blackfire-probe.tar.gz -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire-*.so $(php -r "echo ini_get ('extension_dir');")/blackfire.so \
&& printf "extension=blackfire.so\nblackfire.agent_socket=tcp://blackfire:8707\n" > $PHP_INI_DIR/conf.d/blackfire.ini \
&& rm -rf /tmp/blackfire /tmp/blackfire-probe.tar.gz \
&& mkdir -p /tmp/blackfire \
&& curl -A "Docker" -L https://blackfire.io/api/v1/releases/client/linux_static/amd64 | tar zxp -C /tmp/blackfire \
&& mv /tmp/blackfire/blackfire /usr/bin/blackfire \
&& rm -Rf /tmp/blackfire

WORKDIR $APP_DIR

CMD ["/bin/bash", "-c"]
15 changes: 15 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection.log"
},
"mutators": {
"@default": true
},
"testFramework":"phpunit"
}
2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
backupGlobals="false"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
verbose="true">

<filter>
Expand Down
Loading

0 comments on commit d1d1bec

Please sign in to comment.