2017 © Pedro Peláez
 

symfony-bundle mockery-bundle

This Bundle provides Mockery integration to make it possible to mock service in Behat.

image

polishsymfonycommunity/mockery-bundle

This Bundle provides Mockery integration to make it possible to mock service in Behat.

  • Friday, June 29, 2012
  • by jakzal
  • Repository
  • 0 Watchers
  • 16 Stars
  • 275 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PSSMockeryBundle

Note: Since Behat 2.4 got its own extension system this bundle is replaced by Symfony2MockerExtension., (*1)

Build Status, (*2)

Symfony2 Mockery integration bundle. Currently it supports service mocking., (*3)

Installation

Add PSSMockeryBundle to your composer.json:, (*4)

{
    "require": {
        "polishsymfonycommunity/mockery-bundle": "*"
    }
}

Usage

Replace base container class for test environment in app/AppKernel.php::, (*5)

/**
 * @return string
 */
protected function getContainerBaseClass()
{
    if ('test' == $this->environment) {
        return '\PSS\Bundle\MockeryBundle\DependencyInjection\MockerContainer';
    }

    return parent::getContainerBaseClass();
}

Clear your cache, (*6)

To use it with Behat enable sub-context in your FeatureContext class::, (*7)

/**
 * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
 *
 * @return null
 */
public function __construct(HttpKernelInterface $kernel)
{
    parent::__construct($kernel);

    $this->useContext('container', new \PSS\Bundle\MockeryBundle\Behat\Context\MockerContainerContext($kernel));
}

Example story::, (*8)

Feature: Submitting contact request form
  As a Visitor
  I want to contact sales
  In order to receive more information

  Scenario: Submitting the form
    When I go to "/contact-us"
     And I complete the contact us form with following information
       |First name|Last name|Email                |
       |Jakub     |Zalas    |jzalas+spam@gmail.com|
     And CRM API is available
     And I submit the contact us form
    Then the contact request should be sent to the CRM

Step definitions::, (*9)

/**
 * @Given /^CRM API is available$/
 *
 * @return null
 */
public function crmApiIsAvailable()
{
    $this->getMainContext()->getSubContext('container')
        ->mockService('crm.client', 'PSS\Crm\Client')
        ->shouldReceive('send')
        ->once()
        ->andReturn(true);
}

/**
 * @Given /^(the )?contact request should be sent to (the )?CRM$/
 *
 * @return null
 */
public function theContactRequestShouldBeSentToCrm()
{
    return new Then(sprintf('the "%s" service should meet my expectations', 'crm.client'));
}

All the expectations are checked automatically with an @afterScenario hook. Doing it manually only improves the readability of the scenario and gives better error message., (*10)

To discuss

  • Does it have to be a bundle? Currently it's rather a Symfony independent library.
  • Is this the right approach/implementation?
  • Do we need more features?

The Versions

29/06 2012

dev-master

9999999-dev http://symfonylab.pl

This Bundle provides Mockery integration to make it possible to mock service in Behat.

  Sources   Download

MIT

The Requires

 

bdd tdd test mock mockery behat

02/03 2012

v1.0.0

1.0.0.0 http://symfonylab.pl

This Bundle provides Mockery integration to make it possible to mock service in Behat.

  Sources   Download

MIT

The Requires

 

bdd tdd test mock mockery behat