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