Skip to content

Commit aa21493

Browse files
authored
Adds phpunit and nightwatch testing capability (#41)
* Adds ddev (web) phpunit and nightwatch commands * Adds phpunit/phpunit and phpspec/prophecy-phpunit * Adds chromedriver container
1 parent ad95053 commit aa21493

File tree

8 files changed

+76
-5
lines changed

8 files changed

+76
-5
lines changed

.ddev/commands/web/nightwatch

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
## Description: Run Nightwatch
4+
## Usage: nightwatch [flags] [args]
5+
## Example: "ddev nightwatch" or "ddev nightwatch --tag core"
6+
7+
# Installs dependencies if not already run.
8+
if [ ! -d /var/www/html/web/core/node_modules ]; then
9+
yarn --cwd /var/www/html/web/core install
10+
fi
11+
12+
yarn --cwd /var/www/html/web/core test:nightwatch $@
13+

.ddev/commands/web/phpunit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
## Description: Run PHPUnit
4+
## Usage: phpunit [flags] [args]
5+
## Example: "ddev phpunit --group big_pipe" or "ddev phpunit core/modules/action"
6+
7+
mkdir -p /var/www/html/web/sites/simpletest/browser_output
8+
9+
cd web
10+
11+
BROWSERTEST_OUTPUT_DIRECTORY=/var/www/html/web/sites/simpletest/browser_output \
12+
BROWSERTEST_OUTPUT_BASE_URL=http://localhost:8080 \
13+
SIMPLETEST_DB="mysql://db:db@db/db" \
14+
SIMPLETEST_BASE_URL="http://localhost" \
15+
php ../vendor/bin/phpunit -c core/phpunit.xml.dist $@

.ddev/docker-compose.testing.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# Adds Chromedriver and Drupal PHPUnit test environment variables for running tests.
3+
version: '3.6'
4+
services:
5+
chromedriver:
6+
image: drupalci/chromedriver:production
7+
container_name: ddev-${DDEV_SITENAME}-chromedriver
8+
labels:
9+
com.ddev.site-name: ${DDEV_SITENAME}
10+
com.ddev.approot: $DDEV_APPROOT
11+
12+
web:
13+
links:
14+
- chromedriver:$DDEV_HOSTNAME
15+
environment:
16+
# PHPUnit
17+
SYMFONY_DEPRECATIONS_HELPER: weak
18+
SIMPLETEST_DB: mysql://db:db@db:3306/db
19+
SIMPLETEST_BASE_URL: http://localhost
20+
BROWSERTEST_OUTPUT_DIRECTORY: /var/www/html/private/browsertest_output
21+
BROWSERTEST_OUTPUT_BASE_URL: $DDEV_PRIMARY_URL
22+
MINK_DRIVER_ARGS_WEBDRIVER: '["chrome", {"browserName":"chrome","chromeOptions":{"args":["--disable-gpu","--headless", "--no-sandbox"]}}, "http://chromedriver:9515"]'
23+
24+
# Nightwatch
25+
DRUPAL_TEST_BASE_URL: http://web
26+
DRUPAL_TEST_DB_URL: mysql://db:db@db:3306/db
27+
DRUPAL_TEST_WEBDRIVER_HOSTNAME: chromedriver
28+
DRUPAL_TEST_WEBDRIVER_PORT: 9515
29+
DRUPAL_TEST_CHROMEDRIVER_AUTOSTART: 'false'
30+
DRUPAL_TEST_WEBDRIVER_CHROME_ARGS: "--disable-gpu --headless --no-sandbox"
31+
DRUPAL_NIGHTWATCH_OUTPUT: reports/nightwatch
32+
DRUPAL_NIGHTWATCH_IGNORE_DIRECTORIES: node_modules,vendor,.*,sites/*/files,sites/*/private,sites/simpletest

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Drupal
2-
web/
3-
vendor/
2+
/web/
3+
/vendor/
44
composer.json
55
composer.lock
66
.editorconfig

.gitpod/drupal/drupalpod-setup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ GITMODULESEND
107107
ddev composer require --no-update \
108108
"drupal/core-composer-scaffold:""$DP_CORE_VERSION" \
109109
"drupal/core-project-message:""$DP_CORE_VERSION" \
110-
"drupal/core-recommended:""$DP_CORE_VERSION"
110+
"drupal/core-recommended:""$DP_CORE_VERSION" \
111+
"drupal/core-dev:""$DP_CORE_VERSION"
111112
fi
112113
fi
113114

.gitpod/drupal/templates/drupal-recommended-project-composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"composer/installers": "^1.9",
1919
"drupal/core-composer-scaffold": "^9.2",
2020
"drupal/core-project-message": "^9.2",
21-
"drupal/core-recommended": "^9.2"
21+
"drupal/core-recommended": "^9.2",
22+
"drupal/core-dev": "^9.2"
2223
},
2324
"conflict": {
2425
"drupal/drupal": "*"
@@ -85,4 +86,4 @@
8586
]
8687
}
8788
}
88-
}
89+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ No computer is needed because it is all running in the cloud.
1212

1313
* Install additional packages - `ddev composer`
1414
* Run Drush commands - `ddev drush <command>`
15+
* Run tests
16+
* Nightwatch - `ddev nightwatch <arguments>`
17+
* PHPUnit - `ddev phpunit <arguments>`
1518
* IDE in a browser
1619
* VScode (default)
1720
* PHPStorm - run `phpstorm`

src/vscode-extension/drupalpod-ext/src/help-content.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ body {
8282
<li>Manually test an issue</li>
8383
<li>Write a patch or contribute to an issue fork</li>
8484
<li>Write an automated test</li>
85+
<li>Run automated tests:
86+
<ul>
87+
<li>Nightwatch: <code>ddev nightwatch</code></li>
88+
<li>PHPUnit: <code>ddev phpunit</code></li>
89+
</ul>
90+
</li>
8591
</ul>
8692
</li>
8793
<li>Find your <a href="https://www.drupal.org/community/contributor-guide/find-your-role">role</a> or <a href="https://www.drupal.org/community/contributor-guide/use-or-improve-your-skills">skill</a> to learn more about how to contribute, or ask if anyone needs some help on an issue in #contribute.</li>

0 commit comments

Comments
 (0)