Failed Conditions
Pull Request — master (#12)
by Tibor
03:44
created

ScreenshotExtension::loadExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 4
c 1
b 1
f 0
nc 1
nop 3
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace Bex\Behat\ScreenshotExtension\ServiceContainer;
4
5
use Behat\Testwork\ServiceContainer\Extension;
6
use Behat\Testwork\ServiceContainer\ExtensionManager;
7
use Bex\Behat\ExtensionDriverLocator\DriverLocator;
8
use Bex\Behat\ExtensionDriverLocator\DriverNodeBuilder;
9
use Bex\Behat\ScreenshotExtension\Driver\ImageDriverInterface;
10
use Bex\Behat\ScreenshotExtension\ServiceContainer\Config;
11
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
12
use Symfony\Component\Config\FileLocator;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
15
16
/**
17
 * This class is the entry point of the screenshot extension
18
 *
19
 * It provides debugging functionality by taking a screenshot of a failed tests.
20
 *
21
 * @license http://opensource.org/licenses/MIT The MIT License
22
 */
23
final class ScreenshotExtension implements Extension
24
{
25
    /**
26
     * @var DriverNodeBuilder
27
     */
28
    private $driverNodeBuilder;
29
30
    /**
31
     * Constuctor: init extension
32
     */
33
    public function __construct()
34
    {
35
        $this->driverNodeBuilder = DriverNodeBuilder::getInstance(
36
            Config::IMAGE_DRIVER_NAMESPACE,
37
            Config::IMAGE_DRIVER_PARENT
38
        );
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getConfigKey()
45
    {
46
        return Config::EXTENSION_CONFIG_KEY;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function process(ContainerBuilder $container)
53
    {
54
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function initialize(ExtensionManager $extensionManager)
61
    {
62
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function configure(ArrayNodeDefinition $builder)
69
    {
70
        $builder
71
            ->children()
72
                ->booleanNode(Config::CONFIG_PARAM_EXTENSTION_ENABLED)
73
                    ->defaultTrue()
74
                ->end()
75
                ->enumNode(Config::CONFIG_PARAM_SCREENSHOT_TAKING_MODE)
76
                    ->values(Config::getScreenshotTakingModes())
77
                    ->defaultValue(Config::DEFAULT_SCREENSHOT_TAKING_MODE)
78
                    ->validate()
79
                        ->ifTrue(Config::getScreenshotTakingModeValidator())
80
                        ->thenInvalid(Config::ERROR_MESSAGE_IMAGICK_NOT_FOUND)
81
                    ->end()
82
                ->end()
83
            ->end();
84
85
        $this->driverNodeBuilder->buildDriverNodes(
86
            $builder,
87
            Config::CONFIG_PARAM_ACTIVE_IMAGE_DRIVERS,
88
            Config::CONFIG_PARAM_IMAGE_DRIVER_CONFIGS,
89
            [Config::DEFAULT_IMAGE_DRIVER_KEY]
90
        );
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function load(ContainerBuilder $container, array $config)
97
    {
98
        $extensionConfig = new Config($config);
99
        
100
        if ($extensionConfig->isEnabled()) {
101
            $extensionConfig->loadServices($container);
102
            $container->set(Config::CONFIG_CONTAINER_ID, $extensionConfig);
103
        }
104
    }
105
}
106