|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Lakion 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 Lakion\Behat\MinkDebugExtension\ServiceContainer; |
|
13
|
|
|
|
|
14
|
|
|
use Behat\Testwork\EventDispatcher\ServiceContainer\EventDispatcherExtension; |
|
15
|
|
|
use Behat\Testwork\ServiceContainer\Extension as ExtensionInterface; |
|
16
|
|
|
use Behat\Testwork\ServiceContainer\ExtensionManager; |
|
17
|
|
|
use Lakion\Behat\MinkDebugExtension\Listener\FailedStepListener; |
|
18
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
20
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
21
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Kamil Kokot <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
class MinkDebugExtension implements ExtensionInterface |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* {@inheritdoc} |
|
30
|
|
|
*/ |
|
31
|
|
|
public function load(ContainerBuilder $container, array $config) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->loadStepFailureListener($container); |
|
34
|
|
|
|
|
35
|
|
|
$this->removeAllExistingLogsIfRequested($config); |
|
36
|
|
|
|
|
37
|
|
|
$container->setParameter('mink_debug.directory', $config['directory']); |
|
38
|
|
|
$container->setParameter('mink_debug.screenshot', $config['screenshot']); |
|
39
|
|
|
$container->setParameter('mink_debug.clean_start', $config['clean_start']); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function configure(ArrayNodeDefinition $builder) |
|
46
|
|
|
{ |
|
47
|
|
|
$builder |
|
48
|
|
|
->children() |
|
49
|
|
|
->scalarNode('directory')->isRequired()->end() |
|
50
|
|
|
->booleanNode('screenshot')->defaultFalse()->end() |
|
51
|
|
|
->booleanNode('clean_start')->defaultTrue()->end() |
|
52
|
|
|
->end(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getConfigKey() |
|
59
|
|
|
{ |
|
60
|
|
|
return 'mink_debug'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* {@inheritdoc} |
|
65
|
|
|
*/ |
|
66
|
|
|
public function initialize(ExtensionManager $extensionManager) |
|
67
|
|
|
{ |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritdoc} |
|
72
|
|
|
*/ |
|
73
|
|
|
public function process(ContainerBuilder $container) |
|
74
|
|
|
{ |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param ContainerBuilder $container |
|
79
|
|
|
*/ |
|
80
|
|
|
private function loadStepFailureListener(ContainerBuilder $container) |
|
81
|
|
|
{ |
|
82
|
|
|
$definition = new Definition(FailedStepListener::class, [ |
|
83
|
|
|
new Reference('mink'), |
|
84
|
|
|
'%mink_debug.directory%', |
|
85
|
|
|
'%mink_debug.screenshot%', |
|
86
|
|
|
]); |
|
87
|
|
|
|
|
88
|
|
|
$definition->addTag(EventDispatcherExtension::SUBSCRIBER_TAG, ['priority' => 0]); |
|
89
|
|
|
|
|
90
|
|
|
$container->setDefinition('mink_debug.listener.step_failure', $definition); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param array $config |
|
95
|
|
|
*/ |
|
96
|
|
|
private function removeAllExistingLogsIfRequested(array $config) |
|
97
|
|
|
{ |
|
98
|
|
|
if ($config['clean_start']) { |
|
99
|
|
|
array_map('unlink', glob($config['directory'] . '/*.log')); |
|
100
|
|
|
array_map('unlink', glob($config['directory'] . '/*.png')); |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|