Skip to content

Commit 88fdbb9

Browse files
Patch drupal exit for behat tests #33
2 parents 24a07aa + 0a42e6c commit 88fdbb9

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased] - YYYY-MM-DD
8+
9+
### Fixed
10+
11+
* Certain types of PHP errors did not throw a failed exit code in Behat tests.
12+
[_drupal_log_error() returns a 0 exit code on errors](https://www.drupal.org/project/drupal/issues/2927012)
13+
has been applied to Drupal core until it's fixed upstream. [#33](https://github.com/deviantintegral/drupal_tests/pull/33)
14+
715
## [0.3.0] - 2018-02-21
816

917
### Added

Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,17 @@ RUN cd /var/www/html \
5757

5858
COPY hooks/* /var/www/html/
5959

60+
# Commit our preinstalled Drupal database for faster Behat tests.
6061
COPY drupal.sql.gz /var/www
6162
COPY settings.php /var/www
6263
RUN mkdir -p /var/www/html/sites/default/files/config_yt3arM1I65-zRJQc52H_nu_xyV-c4YyQ86uwM1E3JBCvD3CXL38O8JqAxqnWWj8rHRiigYrj0w/sync \
6364
&& chown -Rv www-data /var/www/html/sites/default/files
6465

66+
# Patch Drupal to avoid a bug where behat failures show as passes.
67+
# https://www.drupal.org/project/drupal/issues/2927012#comment-12467957
68+
RUN cd /var/www/html \
69+
&& curl https://www.drupal.org/files/issues/2927012.22-log-error-exit-code.patch | patch -p1
70+
6571
# Add the vendor/bin directory to the $PATH
6672
ENV PATH="/var/www/html/vendor/bin:${PATH}"
6773

fixtures/behat-fail.patch

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/tests/src/Behat/features/bootstrap/NodeFeatureContext.php b/tests/src/Behat/features/bootstrap/NodeFeatureContext.php
2+
index a02a635..2610535 100644
3+
--- a/tests/src/Behat/features/bootstrap/NodeFeatureContext.php
4+
+++ b/tests/src/Behat/features/bootstrap/NodeFeatureContext.php
5+
@@ -18,6 +18,7 @@ class NodeFeatureContext extends RawDrupalContext implements SnippetAcceptingCon
6+
* @BeforeSuite
7+
*/
8+
public static function prepare(BeforeSuiteScope $scope) {
9+
+ \_drupal_exception_handler(new \Exception());
10+
/** @var \Drupal\Core\Extension\ModuleHandler $moduleHandler */
11+
$moduleHandler = \Drupal::service('module_handler');
12+
if (!$moduleHandler->moduleExists('node')) {

test.sh

+17-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,24 @@ test_ci() {
1616
set -e
1717

1818
# This module fails CS jobs currently so this is more informational.
19-
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-code-sniffer || true
20-
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-unit-kernel-tests
19+
if [ ! -z $1 ]
20+
then
21+
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-code-sniffer || true
22+
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-unit-kernel-tests
23+
24+
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-behat-tests | tee behat.log
25+
# We need to skip colour codes
26+
egrep "1 scenario \\(.*1 passed" behat.log
27+
28+
# Test that a PHP FATAL error properly fails the job.
29+
git apply ../fixtures/behat-fail.patch
2130

22-
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-behat-tests | tee behat.log
23-
# We need to skip colour codes
24-
egrep "1 scenario \\(.*1 passed" behat.log
31+
# circleci doesn't bubble the exit code from behat :(
32+
circleci.sh -e CIRCLE_PROJECT_REPONAME=node build --job run-behat-tests | tee behat.log
33+
grep -A9 'Behat tests failed' behat.log | tail -n 1 | grep '+ exit 1'
34+
35+
git reset --hard HEAD
36+
fi
2537
}
2638

2739
sudo apt-get update -y

0 commit comments

Comments
 (0)