Skip to content

Commit ae9a9c4

Browse files
committed
Merge branch 'release/2.8.0'
2 parents ea3303c + 8b9cb1c commit ae9a9c4

File tree

4 files changed

+95
-112
lines changed

4 files changed

+95
-112
lines changed

bin/travis/before_install.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ phpenv config-rm xdebug.ini
3838
# Install the PECL YAML parser for strict YAML parsing.
3939
yes | pecl install yaml
4040

41+
# Display PHP information.
42+
php -i
43+
4144
# Install Composer optimizations for faster builds.
4245
composer global require \
4346
hirak/prestissimo \

config/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.7.0
1+
v2.8.0

config/packages.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,13 @@ drupal/cog:
115115

116116
acquia/drupal-spec-tool:
117117
type: behat-extension
118-
# The Drupal Spec Tool depends on drupal/drupal-driver, which was not
119-
# compatible with Drupal 9 at the time of this writing.
120-
# @see https://github.com/jhedstrom/DrupalDriver/issues/225
121118
core_matrix:
119+
'>=9.0.0':
120+
version: 4.x
121+
version_dev: 4.x-dev
122122
'^8.7.0':
123123
version: 3.x
124124
version_dev: 3.x-dev
125-
'*':
126-
version: ~
127-
version_dev: ~
128125

129126
drupal/lightning_api:
130127
core_matrix:

src/Task/TestFramework/PhpUnitTask.php

Lines changed: 88 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ class PhpUnitTask extends TestFrameworkBase {
1414

1515
use SutSettingsTrait;
1616

17+
/**
18+
* The DOM document for the PHPUnit configuration file.
19+
*
20+
* @var \DOMDocument
21+
*/
22+
private $doc;
23+
24+
/**
25+
* The XPath helper for the DOM document.
26+
*
27+
* @var \DOMXPath
28+
*/
29+
private $xpath;
30+
1731
/**
1832
* {@inheritdoc}
1933
*/
@@ -44,16 +58,17 @@ public function execute(): void {
4458
*/
4559
private function ensurePhpUnitConfig() {
4660
$path = $this->fixture->getPath('docroot/core/phpunit.xml');
47-
$doc = new \DOMDocument();
48-
$doc->load($path);
49-
$xpath = new \DOMXPath($doc);
61+
$this->doc = new \DOMDocument($path);
62+
$this->doc->load($path);
63+
$this->xpath = new \DOMXPath($this->doc);
5064

5165
$this->ensureSimpleTestDirectory();
52-
$this->setSimpletestSettings($path, $doc, $xpath);
53-
$this->setTestSuite($path, $doc, $xpath);
54-
$this->enableDrupalTestTraits($path, $doc, $xpath);
55-
$this->disableSymfonyDeprecationsHelper($path, $doc, $xpath);
56-
$this->setMinkDriverArguments($path, $doc, $xpath);
66+
$this->setSimpletestSettings();
67+
$this->setTestSuite();
68+
$this->enableDrupalTestTraits();
69+
$this->disableSymfonyDeprecationsHelper();
70+
$this->setMinkDriverArguments();
71+
$this->writeConfiguration($path);
5772
}
5873

5974
/**
@@ -65,123 +80,117 @@ private function ensureSimpleTestDirectory(): void {
6580

6681
/**
6782
* Sets Simpletest settings.
68-
*
69-
* @param string $path
70-
* The path.
71-
* @param \DOMDocument $doc
72-
* The DOM document.
73-
* @param \DOMXPath $xpath
74-
* The XPath object.
7583
*/
76-
private function setSimpletestSettings(string $path, \DOMDocument $doc, \DOMXPath $xpath): void {
77-
$xpath->query('//phpunit/php/env[@name="SIMPLETEST_BASE_URL"]')
84+
private function setSimpletestSettings(): void {
85+
$this->xpath->query('//phpunit/php/env[@name="SIMPLETEST_BASE_URL"]')
7886
->item(0)
7987
->setAttribute('value', sprintf('http://%s', Fixture::WEB_ADDRESS));
80-
$xpath->query('//phpunit/php/env[@name="SIMPLETEST_DB"]')
88+
$this->xpath->query('//phpunit/php/env[@name="SIMPLETEST_DB"]')
8189
->item(0)
8290
->setAttribute('value', 'sqlite://localhost/sites/default/files/.ht.sqlite');
83-
$doc->save($path);
8491
}
8592

8693
/**
8794
* Sets TestSuite config in phpunit.xml.
88-
*
89-
* @param string $path
90-
* The path.
91-
* @param \DOMDocument $doc
92-
* The DOM document.
93-
* @param \DOMXPath $xpath
94-
* The XPath object.
9595
*/
96-
private function setTestSuite(string $path, \DOMDocument $doc, \DOMXPath $xpath): void {
97-
$directory = $doc->createElement('directory', $this->getPath());
98-
$exclude = $doc->createElement('exclude', "{$this->getPath()}/vendor");
99-
$testsuite = $doc->createElement('testsuite');
96+
private function setTestSuite(): void {
97+
$directory = $this->doc->createElement('directory', $this->getPath());
98+
$exclude = $this->doc->createElement('exclude', "{$this->getPath()}/vendor");
99+
$testsuite = $this->doc->createElement('testsuite');
100100
$testsuite->setAttribute('name', 'orca');
101101
$testsuite->appendChild($directory);
102102
$testsuite->appendChild($exclude);
103-
$xpath->query('//phpunit/testsuites')
103+
$this->xpath->query('//phpunit/testsuites')
104104
->item(0)
105105
->appendChild($testsuite);
106-
$doc->save($path);
107106
}
108107

109108
/**
110109
* Sets PHPUnit environment variables so that Drupal Test Traits can work.
111-
*
112-
* @param string $path
113-
* The path.
114-
* @param \DOMDocument $doc
115-
* The DOM document.
116-
* @param \DOMXPath $xpath
117-
* The XPath object.
118110
*/
119-
private function enableDrupalTestTraits(string $path, \DOMDocument $doc, \DOMXPath $xpath): void {
111+
private function enableDrupalTestTraits(): void {
120112
// The bootstrap script is located in ORCA's vendor directory, not the
121113
// fixture's, since ORCA controls the available test frameworks and
122114
// infrastructure.
123-
$xpath->query('//phpunit')
115+
$this->xpath->query('//phpunit')
124116
->item(0)
125117
->setAttribute('bootstrap', "{$this->projectDir}/vendor/weitzman/drupal-test-traits/src/bootstrap.php");
126118

127-
if (!$xpath->query('//phpunit/php/env[@name="DTT_BASE_URL"]')->length) {
128-
$element = $doc->createElement('env');
129-
$element->setAttribute('name', 'DTT_BASE_URL');
130-
$element->setAttribute('value', sprintf('http://%s', Fixture::WEB_ADDRESS));
131-
$xpath->query('//phpunit/php')
132-
->item(0)
133-
->appendChild($element);
134-
}
135-
136-
$doc->save($path);
119+
$this->setEnvironmentVariable('DTT_BASE_URL', sprintf('http://%s', Fixture::WEB_ADDRESS));
120+
$this->setEnvironmentVariable('DTT_MINK_DRIVER_ARGS', $this->getMinkWebDriverArguments());
137121
}
138122

139123
/**
140124
* Disables the Symfony Deprecations Helper.
125+
*/
126+
private function disableSymfonyDeprecationsHelper(): void {
127+
$this->setEnvironmentVariable('SYMFONY_DEPRECATIONS_HELPER', 'disabled');
128+
}
129+
130+
/**
131+
* Sets an environment variable in the PHPUnit configuration.
141132
*
142-
* @param string $path
143-
* The path.
144-
* @param \DOMDocument $doc
145-
* The DOM document.
146-
* @param \DOMXPath $xpath
147-
* The XPath object.
133+
* @param string $name
134+
* The name of the variable to set.
135+
* @param string $value
136+
* The value of the variable to set.
148137
*/
149-
private function disableSymfonyDeprecationsHelper(string $path, \DOMDocument $doc, \DOMXPath $xpath): void {
150-
$result = $xpath->query('//phpunit/php/env[@name="SYMFONY_DEPRECATIONS_HELPER"]');
151-
// Before Drupal 8.6, the tag in question was present and merely needed the
152-
// value changed.
138+
private function setEnvironmentVariable(string $name, string $value): void {
139+
$result = $this->xpath->query(sprintf('//phpunit/php/env[@name="%s"]', $name));
140+
153141
if ($result->length) {
154142
$element = $result->item(0);
155-
$element->setAttribute('value', 'disabled');
156-
$doc->save($path);
143+
$element->setAttribute('value', $value);
157144
}
158-
// Since Drupal 8.6, the tag in question has been commented out and must be
159-
// re-created rather than modified directly.
160145
else {
161-
$element = $doc->createElement('env');
162-
$element->setAttribute('name', 'SYMFONY_DEPRECATIONS_HELPER');
163-
$element->setAttribute('value', 'disabled');
164-
$xpath->query('//phpunit/php')
146+
$element = $this->doc->createElement('env');
147+
$element->setAttribute('name', $name);
148+
$element->setAttribute('value', $value);
149+
$this->xpath->query('//phpunit/php')
165150
->item(0)
166151
->appendChild($element);
167-
$doc->save($path);
168152
}
169153
}
170154

171155
/**
172156
* Sets the mink driver arguments.
173-
*
174-
* @param string $path
175-
* The path.
176-
* @param \DOMDocument $doc
177-
* The DOM document.
178-
* @param \DOMXPath $xpath
179-
* The XPath object.
180157
*/
181-
private function setMinkDriverArguments(string $path, \DOMDocument $doc, \DOMXPath $xpath): void {
158+
private function setMinkDriverArguments(): void {
182159
// Create an <env> element containing a JSON array which will control how
183160
// the Mink driver interacts with Chromedriver.
184-
$mink_arguments = json_encode([
161+
$this->setEnvironmentVariable('MINK_DRIVER_ARGS_WEBDRIVER', $this->getMinkWebDriverArguments());
162+
}
163+
164+
/**
165+
* Writes the PHPUnit configuration to disk.
166+
*
167+
* When dumping the XML document tree, PHP will encode all double quotes in
168+
* the JSON string to &quot;, since the XML attribute value is itself
169+
* enclosed in double quotes. There's no way to change this behavior, so we
170+
* must do a string replacement in order to wrap the Mink driver arguments
171+
* in single quotes.
172+
*
173+
* @param string $path
174+
* The path at which to write the configuration.
175+
*
176+
* @see https://stackoverflow.com/questions/5473520/php-dom-and-single-quotes#5473718
177+
*/
178+
private function writeConfiguration(string $path): void {
179+
$mink_arguments = $this->getMinkWebDriverArguments();
180+
$search = sprintf('value="%s"', htmlentities($mink_arguments));
181+
$replace = sprintf("value='%s'", $mink_arguments);
182+
$xml = str_replace($search, $replace, $this->doc->saveXML());
183+
file_put_contents($path, $xml);
184+
}
185+
186+
/**
187+
* Returns JSON-encoded arguments for the Mink WebDriver driver.
188+
*
189+
* @return string
190+
* The arguments for the WebDriver Mink driver, encoded as JSON.
191+
*/
192+
private function getMinkWebDriverArguments(): string {
193+
return json_encode([
185194
'chrome',
186195
[
187196
'chrome' => [
@@ -197,32 +206,6 @@ private function setMinkDriverArguments(string $path, \DOMDocument $doc, \DOMXPa
197206
],
198207
'http://localhost:4444',
199208
], JSON_UNESCAPED_SLASHES);
200-
201-
$name_attribute = 'MINK_DRIVER_ARGS_WEBDRIVER';
202-
$expression = "//phpunit/php/env[@name='{$name_attribute}']";
203-
204-
if (!$xpath->query($expression)->length) {
205-
$element = $doc->createElement('env');
206-
$element->setAttribute('name', $name_attribute);
207-
$xpath->query('//phpunit/php')
208-
->item(0)
209-
->appendChild($element);
210-
}
211-
212-
$xpath->query($expression)
213-
->item(0)
214-
->setAttribute('value', $mink_arguments);
215-
216-
// When dumping the XML document tree, PHP will encode all double quotes in
217-
// the JSON string to &quot;, since the XML attribute value is itself
218-
// enclosed in double quotes. There's no way to change this behavior, so
219-
// we must do a string replacement in order to wrap the Mink driver
220-
// arguments in single quotes.
221-
// @see https://stackoverflow.com/questions/5473520/php-dom-and-single-quotes#5473718
222-
$search = sprintf('value="%s"', htmlentities($mink_arguments));
223-
$replace = sprintf("value='%s'", $mink_arguments);
224-
$xml = str_replace($search, $replace, $doc->saveXML());
225-
file_put_contents($path, $xml);
226209
}
227210

228211
/**

0 commit comments

Comments
 (0)