SkipTestsExtension   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 74
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigKey() 0 4 1
A process() 0 4 1
A initialize() 0 4 1
A configure() 0 19 1
A load() 0 8 1
A getSkipTagsInitializer() 0 7 3
1
<?php
2
3
namespace Bex\Behat\SkipTestsExtension\ServiceContainer;
4
5
use Behat\Testwork\ServiceContainer\Extension;
6
use Behat\Testwork\ServiceContainer\ExtensionManager;
7
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
8
use Symfony\Component\Config\FileLocator;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
11
12
/**
13
 * This class is the entry point of the extension
14
 *
15
 * @license http://opensource.org/licenses/MIT The MIT License
16
 */
17
class SkipTestsExtension implements Extension
18
{
19
    const CONFIG_KEY = 'skiptests';
20
21
     /**
22
     * {@inheritdoc}
23
     */
24
    public function getConfigKey()
25
    {
26
        return self::CONFIG_KEY;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function process(ContainerBuilder $container)
33
    {
34
        // nothing to do here
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function initialize(ExtensionManager $extensionManager)
41
    {
42
        // nothing to do here
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function configure(ArrayNodeDefinition $builder)
49
    {
50
        $builder
51
            ->children()
52
                ->booleanNode(Config::CONFIG_PARAM_SKIP_SCENARIOS)
53
                    ->defaultTrue()
54
                ->end()
55
                ->booleanNode(Config::CONFIG_PARAM_SKIP_FEATURES)
56
                    ->defaultTrue()
57
                ->end()
58
                ->arrayNode(Config::CONFIG_PARAM_SKIP_TAGS)
59
                    ->defaultValue(['pending', 'skip'])
60
                    ->beforeNormalization()
61
                        ->always($this->getSkipTagsInitializer())
62
                    ->end()
63
                    ->prototype('scalar')->end()
64
                ->end()
65
            ->end();
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function load(ContainerBuilder $container, array $config)
72
    {
73
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/config'));
74
        $loader->load('services.xml');
75
76
        $extensionConfig = new Config($config);
77
        $container->set('bex.skip_tests_extension.config', $extensionConfig);
78
    }
79
80
    /**
81
     * @return \Closure
82
     */
83
    private function getSkipTagsInitializer()
84
    {
85
        return function ($value) {
86
            $value = empty($value) ? ['pending', 'skip'] : $value;
87
            return is_array($value) ? $value : [$value];
88
        };
89
    }
90
}
91