2017 © Pedro Peláez
 

behat-extension zf2behat-extension

Zend Framework 2 extension for Behat

image

mvlabs/zf2behat-extension

Zend Framework 2 extension for Behat

  • Tuesday, March 3, 2015
  • by mauipipe
  • Repository
  • 9 Watchers
  • 21 Stars
  • 5,169 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 15 Forks
  • 2 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

, (*1)

mvlabs/zf2behat-extension

Behat extension for Zend Framework 2 inspired by Symfony2extension by Konstantin Kudryashov., (*2)

Behat (http://behat.org/) is a php framework for Behavior Driven Development. This extension allows you to use it in your Zend Framework 2 projects. It initializes Behat, allowing you to quickly use your Gherking features within ZF2., (*3)

1.Requirements

This extension is installed through composer and has following dependencies:, (*4)

"php":">=5.3.3",
"behat/behat":"=2.4@stable",
"zendframework/zendframework":">=2.2.0"

Composer will take care of installing these for you (see below)., (*5)

2.Installation

In order to install this extension, you only need to add the following in your Zend Framework 2 composer.json:, (*6)

"require": {
     "mvlabs/zf2behat-extension" : "dev-master"
}

and then run composer.phar install (or update). At this point, you need to create a file named behat.yml in your application root folder with following content:, (*7)

default:
 extensions:
    MvLabs\Zf2Extension\Zf2Extension:

3.Usage

If you don't have an existing test suite, please proceed to 4.Initialization within a Module. Otherwise, you can use this extension within your existing test suite in 2 different ways:, (*8)

  1. If you are using php version 5.4+, you can use MvLabs\Zf2BehatExtension\Context\Zf2Dictionary trait which provides basic ZendFramework 2 functionality. This functionality can only be used in one Context though.
  2. You can implement the MvLabs\Zf2BehatExtension\Context\Zf2AwareContextInterface for every context, avoiding to call parent context from subcontexts.

Both methods call a method setZf2App(Application $zf2Application) needed to set in a private property Zend\Mvc\Application to be reused on every step needed, (*9)

4.Initialization inside a Module

In order to initialize your feature suite inside a Zend Framework 2 module, you need to execute:, (*10)

$ php bin\behat --init "<module name>"

So, for example, if you want to initialize the skeleton application, you could just do from your application root directory:, (*11)

vendor/bin/behat --init Application

After the command is executed it will create a Features folder inside your module with a extension ready FeatureContext inside the Context subfolder. You should see following output in console:, (*12)

+d module/<module name>/src/<module name>/Features - place your *.feature files here
+f module/<module name>/src/<module name>/Features/Context/FeatureContext.php - place your feature related code here

5.Running your features

Now that you have your Features directory within your module source folder (module//src/) you can create your first feature file in Gherkin. Please refer to the official behat documentation (http://docs.behat.org/quick_intro.html#define-your-feature) to see how to create your first feature file., (*13)

At this point, you only need to run:, (*14)

vendor/bin/behat <module_name> 

to run the feature against your module., (*15)

6.Feature profiles

If you often find yourself running a specific module suite it's possible to set a module parameter inside a profile in your behat.yml file like in the example below:, (*16)

default:
  extensions:
      MvLabs\Zf2Extension\Zf2Extension:
        module: <module_name>

You can then just call behat without arguments:, (*17)

vendor/bin/behat

Within a profile you can use a specific Zend Framework config/application.config.php file, through the following:, (*18)

default:
  extensions:
      MvLabs\Zf2Extension\Zf2Extension:
        module: <module_name>
    config: <my_custom_config_file_path>

7.Multiple feature profiles

You can also use multiple profiles, such in the example below:, (*19)

default:
  extensions:
      MvLabs\Zf2Extension\Zf2Extension:
        module: User

example:
   extensions:
      MvLabs\Zf2Extension\Zf2Extension:
        module: Albums

After setting those profiles, you can your Albums module suite executing:, (*20)

``` $ php bin\behat -p=example, (*21)




8.Specific Feature Execution ============================ You can run specific features specifying file name:

$ php bin\behat "", (*22)




9.Appication Level Feature Suite ============================== If you don't want to use module-centric structure it's possible maitain an application structure specifing a features path and context class in your behat.yml file like in the example:

default: paths: features: features context: class: ModuleDemo\Features\Context\CustomContext ```, (*23)

Using this path you shuold only remember to add your context class in the autoloader., (*24)

10.Configuration Parameters

Supported options for profiles are:, (*25)

  1. module - set the module to be runned for a specific profile (only one module per profile is currently supported)
  2. config - set a custom configuration file. if it is not specified config/application.config.php will be loaded

The Versions

03/03 2015

dev-master

9999999-dev

Zend Framework 2 extension for Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Contavalli

zf2 behat extension mvlabs

05/09 2013

dev-develop

dev-develop

Zend Framework 2 extension for Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Contavalli

16/07 2013

0.5

0.5.0.0

Zend Framework 2 extension for Behat

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Contavalli