2017 © Pedro Peláez
 

library behat-utils-extension

A set of utility for Behat3

image

yoanm/behat-utils-extension

A set of utility for Behat3

  • Sunday, January 22, 2017
  • by yoanm
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4,186 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 13 Versions
  • 19 % Grown

The README.md

BehatUtilsExtension

Scrutinizer Build Status Scrutinizer Code Quality Code Coverage, (*1)

Travis Build Status PHP Versions, (*2)

Latest Stable Version, (*3)

BehatUtilsExtension provide a set of utility for Behat 3.0+, (*4)

Install

composer require --dev yoanm/behat-utils-extension

How to use

BehatUtilsExtension require behat/behat and monolog/monolog, (*5)

Configuration

Add the following in your behat configuration file (usually behat.yml) :, (*6)

default:
    extensions:
        Yoanm\BehatUtilsExtension: ~

In the box

Logger

See LoggerAwareInterface, (*7)

Implements this interface and your context will have a logger injected, (*8)

Example

<?php
namespace Functional\Yoanm\BehatUtilsExtension\Context;

use Behat\Behat\Context\Context;
use Psr\Log\LoggerInterface;
use Yoanm\BehatUtilsExtension\Context\LoggerAwareInterface;

class FeatureContext implements Context, LoggerAwareInterface
{
    /** @var LoggerInterface */
    private $logger;

    /**
     * {@inheritdoc}
     */
    public function setBehatLogger(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * @When my step
     */
    public function myStep()
    {
        $this->logger->info('Executing my step');
    }
}

Behat event subscription

See BehatContextSubscriberInterface, (*9)

Enable initializer and implements BehatContextSubscriberInterface, then your context will be passed to Behat dispatcher in order to receive behat events, (*10)

Enable context initializer

default:
    extensions:
        Yoanm\BehatUtilsExtension:
            event_subscriber: true

Example

<?php
namespace Functional\Yoanm\BehatUtilsExtension\Context;

use Behat\Behat\Context\Context;
use Behat\Behat\EventDispatcher\Event\ExampleTested;
use Behat\Behat\EventDispatcher\Event\GherkinNodeTested;
use Behat\Behat\EventDispatcher\Event\ScenarioTested;
use Yoanm\BehatUtilsExtension\Context\BehatContextSubscriberInterface;

class FeatureContext implements Context, BehatContextSubscriberInterface
{
    /**
     * @param GherkinNodeTested $event
     */
    public function reset(GherkinNodeTested $event)
    {
        /**
         * Reset here your data before a scenario or example is started
         */
    }

    /**
     * {@inheritdoc}
     */
    public static function getSubscribedEvents()
    {
        return [
            ScenarioTested::BEFORE => ['reset'],
            ExampleTested::BEFORE => ['reset'],
            //Or
            // ScenarioTested::BEFORE => ['reset', ListenerPriority::HIGH_PRIORITY],
        ];
    }
}

Step logger

See BehatStepLoggerSubscriber, (*11)

If enabled, will log each behat feature/background/outline/example/step start and end. Usefull to understand what happens behing the scene if you have a non understandable error in you features., (*12)

Could be use with Logger to easily spot an issue in context custom steps., (*13)

Enable step listener

default:
    extensions:
        Yoanm\BehatUtilsExtension:
            step_logger: true

Output example

The following will be appended in the configured log file (see default configuration reference below)., (*14)

behatUtils.DEBUG: [BehatStepLoggerSubscriber] [FEATURE][IN] {"title":"FEATURE TITLE","file":"FEATURE FILE PATH"} []
behatUtils.DEBUG: [BehatStepLoggerSubscriber] [FEATURE][OUT] {"title":"FEATURE TITLE","file":"FEATURE FILE PATH"} []

behatUtils.DEBUG: [BehatStepLoggerSubscriber] [BACKGROUND][IN] {"title":"BACKGROUND TITLE","line":"BACKGROUND START LINE"} []
behatUtils.DEBUG: [BehatStepLoggerSubscriber] [BACKGROUND][OUT] {"title":"BACKGROUND TITLE","line":"BACKGROUND END LINE"} []

behatUtils.DEBUG: [BehatStepLoggerSubscriber] [OUTLINE][IN] {"title":"OUTLINE TITLE","line": "OUTLINE START LINE"} []
behatUtils.DEBUG: [BehatStepLoggerSubscriber] [OUTLINE][OUT] {"title":"OUTLINE TITLE","line": "OUTLINE END LINE"} []

behatUtils.DEBUG: [BehatStepLoggerSubscriber] [EXAMPLE][IN] {"tokens":{"EXAMPLE_TOKENS_NAME":"EXAMPLE_TOKENS_VALUE"},"title":"| EXAMPLE_TOKENS_VALUE|","line":"EXAMPLE START LINE"} []
behatUtils.DEBUG: [BehatStepLoggerSubscriber] [EXAMPLE][OUT] {"tokens":{"EXAMPLE_TOKENS_NAME":"EXAMPLE_TOKENS_VALUE"},"title":"| EXAMPLE_TOKENS_VALUE|","line":"EXAMPLE END LINE"} []

behatUtils.DEBUG: [BehatStepLoggerSubscriber] [STEP][IN] {"text":"STEP TEXT","line":"STEP LINE"} []
behatUtils.DEBUG: [BehatStepLoggerSubscriber] [STEP][OUT] {"text":"STEP TEXT","line":"STEP LINE"} []

Configuration reference

default:
    extensions:
        Yoanm\BehatUtilsExtension:
            logger:
                path: behat.log
                level: INFO
            event_subscriber: false
            step_logger: false

Tests

This repository follow a custom test strategy, (*15)

Contributing

See contributing note, (*16)

The Versions

22/01 2017

dev-master

9999999-dev

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

22/01 2017

0.7.0

0.7.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

22/01 2017

dev-release/0.7.0

dev-release/0.7.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

22/01 2017

dev-feature/compliance

dev-feature/compliance

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

02/01 2017

0.6.0

0.6.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

02/01 2017

0.5.0

0.5.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

01/01 2017

0.4.0

0.4.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

31/12 2016

0.3.0

0.3.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

29/12 2016

0.2.0

0.2.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

29/12 2016

0.1.3

0.1.3.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

29/12 2016

0.1.2

0.1.2.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

29/12 2016

0.1.1

0.1.1.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3

29/12 2016

0.1.0

0.1.0.0

A set of utility for Behat3

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar yoanm

debug logger utils behat3