Code Monkey home page Code Monkey logo

driver-testsuite's Introduction

Mink Driver testsuite

This is the common testsuite for Mink drivers to ensure consistency among implementations.

Usage

The testsuite of a driver should be based as follow:

{
    "require": {
        "behat/mink": "~1.7"
    },
    
    "require-dev": {
        "mink/driver-testsuite": "dev-master"
    },

    "autoload-dev": {
        "psr-4": {
            "Acme\\MyDriver\\Tests\\": "tests"
        }
    }
}

The PHPUnit config should look like this:

<?xml version="1.0" encoding="UTF-8"?>

<phpunit colors="true" bootstrap="vendor/autoload.php">
    <php>
        <var name="driver_config_factory" value="Acme\MyDriver\Tests\Config::getInstance" />
    </php>

    <testsuites>
        <testsuite name="Functional tests">
            <directory>vendor/mink/driver-testsuite/tests</directory>
        </testsuite>
        <!-- if needed to add more tests -->
        <testsuite name="Driver tests">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>./src</directory>
        </whitelist>
    </filter>
</phpunit>

Then create the driver config for the testsuite:

// tests/Config.php

namespace Acme\MyDriver\Tests;

use Behat\Mink\Tests\Driver\AbstractConfig;

class Config extends AbstractConfig
{
    /**
     * Creates an instance of the config.
     *
     * This is the callable registered as a php variable in the phpunit.xml config file.
     * It could be outside the class but this is convenient.
     */
    public static function getInstance()
    {
        return new self();
    }

    /**
     * Creates driver instance.
     *
     * @return \Behat\Mink\Driver\DriverInterface
     */
    public function createDriver()
    {
        return new \Acme\MyDriver\MyDriver();
    }
}

Some other methods are available in the AbstractConfig which can be overwritten to adapt the testsuite to the needs of the driver (skipping some tests for instance).

Running tests

Before running tests, you need to start the webserver exposing the web fixtures (unless the driver does not perform real HTTP requests). This is done using this command:

$ vendor/bin/mink-test-server

To stop the server at the end of tests, cancel the command.

Note: this command requires Bash. If you are on Windows, use either GitBash or Cygwin (or another equivalent tool) to launch it.

This command also requires PHP 5.4+ to be able to use the builtin webserver. If the PHP version available in the PATH is a different one, use the MINK_PHP_BIN env variable to select a different PHP runtime.

You can now run tests for your driver with phpunit.

Adding Driver-specific Tests

When adding extra test cases specific to the driver, either use your own namespace or put them in the Behat\Mink\Tests\Driver\Custom subnamespace to ensure that you will not create conflicts with test cases added in the driver testsuite in the future.

driver-testsuite's People

Contributors

acoulton avatar stof avatar uuf6429 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.