1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Robo\Tasks; |
4
|
|
|
use Symfony\Component\Finder\Finder; |
5
|
|
|
use Symfony\Component\Yaml\Yaml; |
6
|
|
|
use Drupal\Component\Utility\NestedArray; |
7
|
|
|
|
8
|
|
|
class RoboFile extends Tasks { |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The default URL of the Drupal site. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
const BASE_URL = 'http://127.0.0.1:8080'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* {@inheritdoc} |
19
|
|
|
*/ |
20
|
|
|
protected function taskBehat($behat = NULL) { |
21
|
|
|
return parent::taskBehat($behat ?: 'vendor/bin/behat') |
22
|
|
|
->config('.behat.yml') |
23
|
|
|
->format('pretty') |
24
|
|
|
->option('colors') |
25
|
|
|
->option('stop-on-failure') |
26
|
|
|
->option('strict'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function taskDrupal($command, $console = NULL) { |
30
|
|
|
return $this->taskExec($console ?: '../vendor/bin/drupal') |
31
|
|
|
->rawArg($command) |
32
|
|
|
->dir('docroot'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function taskDrush($command, $drush = NULL) { |
36
|
|
|
return $this->taskExec($drush ?: '../vendor/bin/drush') |
37
|
|
|
->rawArg($command) |
38
|
|
|
->dir('docroot'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Configures Behat. |
43
|
|
|
* |
44
|
|
|
* @param string $base_url |
45
|
|
|
* (optional) The URL of the Drupal site. |
46
|
|
|
* |
47
|
|
|
* @return \Robo\Contract\TaskInterface |
48
|
|
|
* The task to execute. |
49
|
|
|
*/ |
50
|
|
|
public function configureBehat ($base_url = NULL) { |
51
|
|
|
$configuration = []; |
52
|
|
|
|
53
|
|
|
/** @var Finder $partials */ |
54
|
|
|
$partials = Finder::create()->in('docroot')->files()->name('behat.partial.yml'); |
55
|
|
|
|
56
|
|
|
foreach ($partials as $partial) { |
57
|
|
|
$partial = str_replace( |
58
|
|
|
'%paths.base%', |
59
|
|
|
$partial->getPathInfo()->getRealPath(), |
60
|
|
|
$partial->getContents() |
61
|
|
|
); |
62
|
|
|
$configuration = NestedArray::mergeDeep($configuration, Yaml::parse($partial)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if ($configuration) { |
66
|
|
|
$configuration = str_replace([ |
67
|
|
|
'%base_url%', |
68
|
|
|
'%drupal_root%', |
69
|
|
|
], |
70
|
|
|
[ |
71
|
|
|
$base_url ?: static::BASE_URL, |
72
|
|
|
'docroot', |
73
|
|
|
], |
74
|
|
|
Yaml::dump($configuration) |
75
|
|
|
); |
76
|
|
|
return $this->taskWriteToFile('.behat.yml')->text($configuration); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Run Behat tests. |
83
|
|
|
* |
84
|
|
|
* To run all tests, simply run 'test:behat'. To run a specific feature, you |
85
|
|
|
* can pass its path, relative to the tests/features directory: |
86
|
|
|
* |
87
|
|
|
* test:behat media/image.feature |
88
|
|
|
* |
89
|
|
|
* You can omit the .feature extension. This example runs |
90
|
|
|
* tests/features/workflow/diff.feature: |
91
|
|
|
* |
92
|
|
|
* test:behat workflow/diff |
93
|
|
|
* |
94
|
|
|
* This also works with a directory of features. This example runs everything |
95
|
|
|
* in tests/features/media: |
96
|
|
|
* |
97
|
|
|
* test:behat media |
98
|
|
|
* |
99
|
|
|
* Any command-line options after the initial -- will be passed unmodified to |
100
|
|
|
* Behat. So you can filter tests by tags, like normal: |
101
|
|
|
* |
102
|
|
|
* test:behat -- --tags=javascript,~media |
103
|
|
|
* |
104
|
|
|
* This command will start Selenium Server in the background during the test |
105
|
|
|
* run, to support functional JavaScript tests. |
106
|
|
|
*/ |
107
|
|
|
public function testBehat(array $arguments) { |
108
|
|
|
$this |
109
|
|
|
->taskExec('vendor/bin/selenium-server-standalone') |
110
|
|
|
->rawArg('-port 4444') |
111
|
|
|
->rawArg('-log selenium.log') |
112
|
|
|
->background() |
113
|
|
|
->run(); |
114
|
|
|
|
115
|
|
|
$task = $this->taskBehat(); |
116
|
|
|
|
117
|
|
|
foreach ($arguments as $argument) { |
118
|
|
|
if ($argument{0} == '-') { |
119
|
|
|
$task->rawArg($argument); |
120
|
|
|
} |
121
|
|
|
else { |
122
|
|
|
$feature = "tests/features/$argument"; |
123
|
|
|
|
124
|
|
|
if (file_exists("$feature.feature")) { |
125
|
|
|
$feature .= '.feature'; |
126
|
|
|
} |
127
|
|
|
$task->arg($feature); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
return $task; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|