Skip to content
This repository has been archived by the owner on Nov 29, 2017. It is now read-only.

Commit

Permalink
move to behat3
Browse files Browse the repository at this point in the history
  • Loading branch information
tyx committed Aug 28, 2014
1 parent 86e9f2b commit 2926c4d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

Let the mock engine that you want coming to help you in your behat tests by mocking the Symfony services.

*Only Behat 2 supported for now*.
* dev-master : Behat 2.5.x
* dev-behat3 : Behat 3.0.x

## Adapters

Expand Down
20 changes: 15 additions & 5 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,37 @@

namespace Rezzza\MockExtension;

use Behat\Behat\Extension\ExtensionInterface;
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface;
use Behat\Testwork\ServiceContainer\ExtensionManager;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;

class Extension implements ExtensionInterface
{
public function load(array $config, ContainerBuilder $container)
public function getConfigKey()
{
return 'mocker';
}

public function initialize(ExtensionManager $extensionManager)
{
}

public function load(ContainerBuilder $container, array $config)
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/Resources'));
$loader->load('services.xml');
}

public function getConfig(ArrayNodeDefinition $builder)
public function configure(ArrayNodeDefinition $builder)
{
}

public function getCompilerPasses()
public function process(ContainerBuilder $container)
{
return array();
}
}

15 changes: 7 additions & 8 deletions src/MockerAwareInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Rezzza\MockExtension;

use Behat\Behat\Context\ContextInterface;
use Behat\Behat\Context\Initializer\InitializerInterface;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Initializer\ContextInitializer;

class MockerAwareInitializer implements InitializerInterface
class MockerAwareInitializer implements ContextInitializer
{
private $mocker;

Expand All @@ -14,13 +14,12 @@ public function __construct(Mocker $mocker)
$this->mocker = $mocker;
}

public function supports(ContextInterface $context)
public function initializeContext(Context $context)
{
return $context instanceof MockerAware;
}
if (!$context instanceof MockerAware) {
return;
}

public function initialize(ContextInterface $context)
{
$context->setMocker($this->mocker);
}
}
6 changes: 3 additions & 3 deletions src/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<service id="rezzza.mock_extension.mocker" class="Rezzza\MockExtension\Mocker">
<argument type="service" id="behat.symfony2_extension.kernel" />
<argument type="service" id="behat.mink" />
<argument type="service" id="symfony2_extension.kernel" />
<argument type="service" id="mink" />
</service>

<service id="rezzza.mock_extension.initializer" class="Rezzza\MockExtension\MockerAwareInitializer">
<argument type="service" id="rezzza.mock_extension.mocker" />
<tag name="behat.context.initializer" />
<tag name="context.initializer" />
</service>
</services>
</container>

0 comments on commit 2926c4d

Please sign in to comment.