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