Completed
Push — master ( 8b479a...c1c0ed )
by Kamil
18:11
created

IsolatedSymfonyFactory::buildDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\Symfony2Extension\Factory;
13
14
use Behat\Mink\Driver\BrowserKitDriver;
15
use Behat\MinkExtension\ServiceContainer\Driver\DriverFactory;
16
use Behat\Symfony2Extension\Driver\KernelDriver;
17
use Sylius\Behat\Symfony2Extension\ServiceContainer\Symfony2Extension;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
/**
23
 * @author Arkadiusz Krakowiak <[email protected]>
24
 */
25
final class IsolatedSymfonyFactory implements DriverFactory
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getDriverName()
31
    {
32
        return 'symfony2';
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function supportsJavascript()
39
    {
40
        return false;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function configure(ArrayNodeDefinition $builder)
47
    {
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function buildDriver(array $config)
54
    {
55
        $this->assertMinkBrowserKitDriverIsAvailable();
56
57
        return new Definition(KernelDriver::class, [
58
            new Reference(Symfony2Extension::DRIVER_KERNEL_ID),
59
            '%mink.base_url%',
60
        ]);
61
    }
62
63
    /**
64
     * @throws \RuntimeException If MinkBrowserKitDriver is not available
65
     */
66
    private function assertMinkBrowserKitDriverIsAvailable()
67
    {
68
        if (!class_exists(BrowserKitDriver::class)) {
69
            throw new \RuntimeException('Install MinkBrowserKitDriver in order to use the symfony2 driver.');
70
        }
71
    }
72
}
73