Skip to content

Commit

Permalink
Add tests and init configuration support Refs #3 Closes #1
Browse files Browse the repository at this point in the history
* add docker-compose support
* req --dev phpunit/phpunit matthiasnoback/symfony-config-test
so that they support at least php 7.1
* add unit tests and one behat test with chrome
* add PHP 7.4 to travis and adopt script section
* init CHANGELOG.md
  • Loading branch information
robertfausk committed Mar 29, 2020
1 parent 10087b4 commit 338dab1
Show file tree
Hide file tree
Showing 14 changed files with 446 additions and 17 deletions.
14 changes: 9 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ addons:

sudo: false

php: [7.1, 7.2, 7.3]
php: [7.1, 7.2, 7.3, 7.4]

matrix:
allow_failures:
- env: DEPENDENCIES='dev'
- php: 7.3
- php: 7.4
fast_finish: true
include:
# Test against dev versions of dependencies
- php: 7.3
- php: 7.4
env: DEPENDENCIES='dev'
cache:
directories:
Expand All @@ -27,5 +27,9 @@ install:
- composer install --no-progress

script:
- vendor/bin/phpspec run -f pretty
- vendor/bin/behat -fprogress --strict
- vendor/bin/phpunit -v --coverage-clover=coverage.clover
- vendor/bin/behat

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
1.0.1 / 2020-
==================

Features:
* Enabled configuration per driver instance; usage examples with all sessions using mink-panther-driver:
```YAML
# in behat.yml
extensions:
Robertfausk\Behat\PantherExtension: ~ # no configuration here
Behat\MinkExtension:
javascript_session: javascript_chrome
sessions:
default:
panther: ~
javascript:
panther:
options: ~
javascript_chrome:
panther:
options:
browser: 'chrome'
webServerDir: '%paths.base%/public'
javascript_firefox:
panther:
options:
browser: 'firefox'
```
Testsuite:
* Enabled travis at all with phpunit and behat for PHP 7.1-7.4
* Added PHP 7.4 in the CI
* Added Unit Tests
* Added one simple scenario test with behat
1.0.0 / 2019-08-16
==================
Initial Release :tada:
39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG PHP_VERSION=7.2

FROM composer:latest as composer
FROM php:${PHP_VERSION}-cli

# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

RUN apt-get update && apt-get install -y \
git-core


COPY --from=composer /usr/bin/composer /usr/bin/composer

# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /home/docker/.composer
# contains dev-mode packages
RUN composer global require "hirak/prestissimo:^0.3" "sllh/composer-versions-check:^2.0" "pyrech/composer-changelogs:^1.7" --prefer-dist --no-progress --no-suggest --classmap-authoritative

##############################################################
# add symfony/panther
##############################################################
RUN apt-get update && apt-get install -y libzip-dev zlib1g-dev unzip chromium && docker-php-ext-install zip
ENV PANTHER_NO_SANDBOX 1

##############################################################
# add gd
##############################################################

RUN apt-get update && apt-get install -y \
libjpeg-dev \
libpng-dev

RUN docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd

WORKDIR /var/www/html
COPY . /var/www/html
47 changes: 46 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,53 @@ Symfony Panther extension for Behat
composer require --dev robertfausk/behat-panther-extension
```

## Usage example

* Add ```Robertfausk\Behat\PantherExtension: ~``` to your behat.yml.
* Use ```panther``` session in ```Behat\MinkExtension```.
* The extension will use options of ```symfony/panther``` by default.
Have a look at ```PantherTestCaseTrait::$defaultOptions``` for this.
* Following are some examples with all sessions using mink-panther-driver:
```YAML
# in behat.yml
extensions:
Robertfausk\Behat\PantherExtension: ~ # no configuration here
Behat\MinkExtension:
javascript_session: javascript_chrome
sessions:
default:
panther: ~
javascript:
panther:
options: ~
javascript_chrome:
panther:
options:
browser: 'chrome'
webServerDir: '%paths.base%/public' # your custom public dir
javascript_firefox:
panther:
options:
browser: 'firefox'
```
### How to upgrade?
Have a look at [CHANGELOG](CHANGELOG.md) for detailed information.
## How to contribute?
Start docker-compose with php version of your choice. Currently there are php7.2, php7.3 and php7.4.
docker-compose up php7.2
Run phpunit tests
docker-compose run php7.2 vendor/bin/phpunit
## Credits
Created by Robert Freigang [robertfausk](https://github.com/robertfausk).
MinkPantherDriver is built on top of [Panther](https://github.com/symfony/panther) and for usage with [Behat and Mink](http://behat.org/en/latest/cookbooks/integrating_symfony2_with_behat.html#initialising-behat).
BehatPantherExtension is built on top of [symfony/panther](https://github.com/symfony/panther) and [robertfausk/mink-panther-driver]([Panther](https://github.com/robertfausk/mink-panther-driver)).
It is for usage with [Behat and Mink](http://behat.org/en/latest/cookbooks/integrating_symfony2_with_behat.html#initialising-behat).
7 changes: 7 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@
"symfony/config": "^3.4|^4.0"
},
"require-dev": {
"phpunit/phpunit": "~7.5",
"matthiasnoback/symfony-config-test": "^4.1"
},
"autoload": {
"psr-0": {
"Robertfausk\\Behat\\PantherExtension": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: "3"
services:

php7.1:
tty: true
build:
context: .
args:
- PHP_VERSION=7.1
volumes:
- .:/var/www/html

php7.2:
tty: true
build:
context: .
args:
- PHP_VERSION=7.2
volumes:
- .:/var/www/html

php7.3:
tty: true
build:
context: .
args:
- PHP_VERSION=7.3
volumes:
- .:/var/www/html

php7.4:
tty: true
build:
context: .
args:
- PHP_VERSION=7.4
volumes:
- .:/var/www/html
23 changes: 23 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="vendor/autoload.php">
<php>
<var name="driver_config_factory" value="Behat\Mink\Tests\Driver\PantherConfig::getInstance" />
</php>

<extensions>
<extension class="Symfony\Component\Panther\ServerExtension" />
</extensions>

<testsuites>
<testsuite name="Driver test suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Robertfausk\Behat\PantherExtension\ServiceContainer\Driver;

use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
use Robertfausk\Behat\PantherExtension\ServiceContainer\PantherConfiguration;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\Definition;

Expand Down Expand Up @@ -33,17 +34,8 @@ public function supportsJavascript()
*/
public function configure(ArrayNodeDefinition $builder)
{
$builder
->children()
->arrayNode('options')
->useAttributeAsKey('key')
->prototype('variable')->end()
->info(
"These are the options passed as first argument to PantherTestCaseTrait::createPantherClient client constructor."
)
->end()
->end()
;
$configuration = new PantherConfiguration();
$builder->append($configuration->addOptionsNode());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);

namespace Robertfausk\Behat\PantherExtension\ServiceContainer;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* @author Robert Freigang <[email protected]>
*/
class PantherConfiguration implements ConfigurationInterface
{
/**
* @inheritDoc
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('panther');
if (\method_exists($treeBuilder, 'getRootNode')) {
$root = $treeBuilder->getRootNode();
} else {
$root = $treeBuilder->root('panther');
}

$root->append($this->addOptionsNode());

return $treeBuilder;
}

public function addOptionsNode(): ArrayNodeDefinition
{
$treeBuilder = new TreeBuilder('options');

$node = $treeBuilder->getRootNode()
->info(
"These are the options passed as first argument to PantherTestCaseTrait::createPantherClient client constructor."
)
->ignoreExtraKeys()
->scalarPrototype()
->end()
;

return $node;
}
}
29 changes: 29 additions & 0 deletions tests/Behat/behat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
default:
suites:
web:
paths:
- '%paths.base%/features'
contexts:
- Behat\MinkExtension\Context\MinkContext
extensions:
Robertfausk\Behat\PantherExtension: ~ # no configuration here
Behat\MinkExtension:
browser_name: chrome
javascript_session: javascript_chrome
sessions:
default:
panther:
options:
webServerDir: '%paths.base%/public'
javascript:
panther:
options: ~
javascript_chrome:
panther:
options:
browser: 'chrome'
webServerDir: '%paths.base%/public'
javascript_firefox:
panther:
options:
browser: 'firefox'
6 changes: 6 additions & 0 deletions tests/Behat/features/simple.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Feature: Just a simple call to a php script

@javascript_chrome
Scenario: I am on a php and see the echo response
And I am on "index.php"
Then I should see "Huhuuu!"
6 changes: 6 additions & 0 deletions tests/Behat/public/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
declare(strict_types=1);

echo '<div id="output"></div>';

echo '<script type="application/javascript">window.document.getElementById("output").append("Huhuuu!")</script>';
Loading

0 comments on commit 338dab1

Please sign in to comment.