forked from michalochman/SilverStripeExtension
/
Extension.php
69 lines (60 loc) · 2.26 KB
/
Extension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace SilverStripe\BehatExtension;
use Symfony\Component\Config\FileLocator,
Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Behat\Behat\Extension\Extension as BaseExtension;
/*
* This file is part of the SilverStripe\BehatExtension
*
* (c) Michał Ochman <ochman.d.michal@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* SilverStripe extension for Behat class.
*
* @author Michał Ochman <ochman.d.michal@gmail.com>
*/
class Extension extends BaseExtension
{
/**
* Loads a specific configuration.
*
* @param array $config Extension configuration hash (from behat.yml)
* @param ContainerBuilder $container ContainerBuilder instance
*/
public function load(array $config, ContainerBuilder $container)
{
if (!isset($config['framework_path'])) {
throw new \InvalidArgumentException('Specify `framework_path` parameter for silverstripe_extension');
}
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/services'));
$loader->load('silverstripe.yml');
$behat_base_path = $container->getParameter('behat.paths.base');
$config['framework_path'] = realpath(sprintf('%s%s%s',
rtrim($behat_base_path, DIRECTORY_SEPARATOR),
DIRECTORY_SEPARATOR,
ltrim($config['framework_path'], DIRECTORY_SEPARATOR)
));
if (!file_exists($config['framework_path']) || !is_dir($config['framework_path'])) {
throw new \InvalidArgumentException('Path specified as `framework_path` either doesn\'t exist or is not a directory');
}
$container->setParameter('behat.silverstripe_extension.framework_path', $config['framework_path']);
if (isset($config['ajax_steps'])) {
$container->setParameter('behat.silverstripe_extension.ajax_steps', $config['ajax_steps']);
}
}
/**
* Returns compiler passes used by SilverStripe extension.
*
* @return array
*/
public function getCompilerPasses()
{
return array(
new Compiler\MinkExtensionBaseUrlPass(),
);
}
}