Skip to content

Commit

Permalink
Add watch mode for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kajetan Dvoracek committed Mar 24, 2022
1 parent 2f67253 commit a1b9ab4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
16 changes: 13 additions & 3 deletions Build/Test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ services:
set -x
fi
php -v | grep '^PHP'
COMMAND=\"vendor/phpunit/phpunit/phpunit -c Build/Test/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}\"
if [ ${PHPUNIT_WATCH} -eq 0 ]; then
PHPUNIT_BIN=\"vendor/bin/phpunit\"
else
PHPUNIT_BIN=\"vendor/bin/phpunit-watcher watch\"
fi
COMMAND=\"$${PHPUNIT_BIN} -c Build/Test/FunctionalTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE}\"
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
XDEBUG_MODE=\"off\" $${COMMAND};
else
Expand All @@ -121,13 +126,18 @@ services:
set -x
fi
php -v | grep '^PHP'
if [ ${PHPUNIT_WATCH} -eq 0 ]; then
PHPUNIT_BIN=\"vendor/bin/phpunit\"
else
PHPUNIT_BIN=\"vendor/bin/phpunit-watcher watch\"
fi
if [ ${PHP_XDEBUG_ON} -eq 0 ]; then
XDEBUG_MODE=\"off\" \
vendor/phpunit/phpunit/phpunit -c Build/Test/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
$${PHPUNIT_BIN} -c Build/Test/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
else
XDEBUG_MODE=\"debug,develop\" \
XDEBUG_TRIGGER=\"foo\" \
XDEBUG_CONFIG=\"client_port=${PHP_XDEBUG_PORT} client_host=host.docker.internal\" \
vendor/phpunit/phpunit/phpunit -c Build/Test/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
$${PHPUNIT_BIN} -c Build/Test/UnitTests.xml ${EXTRA_TEST_OPTIONS} ${TEST_FILE};
fi
"
11 changes: 10 additions & 1 deletion Build/Test/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ setUpDockerComposeDotEnv() {
echo "DOCKER_PHP_IMAGE=${DOCKER_PHP_IMAGE}"
echo "EXTRA_TEST_OPTIONS=${EXTRA_TEST_OPTIONS}"
echo "SCRIPT_VERBOSE=${SCRIPT_VERBOSE}"
echo "PHPUNIT_WATCH=${PHPUNIT_WATCH}"
echo "DBMS=${DBMS}"
echo "DATABASE_DRIVER=${DATABASE_DRIVER}"
echo "MARIADB_VERSION=${MARIADB_VERSION}"
Expand Down Expand Up @@ -135,6 +136,10 @@ Options:
Send xdebug information to a different port than default 9003 if an IDE like PhpStorm
is not listening on default port.
-w
Only with -s functional|unit
Run tests in watch mode.
-u
Update existing typo3/core-testing-*:latest docker images. Maintenance call to docker pull latest
versions of the main php images. The images are updated once in a while and only the youngest
Expand Down Expand Up @@ -189,6 +194,7 @@ PHP_XDEBUG_ON=0
PHP_XDEBUG_PORT=9003
EXTRA_TEST_OPTIONS=""
SCRIPT_VERBOSE=0
PHPUNIT_WATCH=0
DATABASE_DRIVER=""
MARIADB_VERSION="10.3"
MYSQL_VERSION="5.5"
Expand All @@ -199,7 +205,7 @@ OPTIND=1
# Array for invalid options
INVALID_OPTIONS=();
# Simple option parsing based on getopts (! not getopt)
while getopts ":a:s:t:d:i:j:p:e:xy:huv" OPT; do
while getopts ":a:s:t:d:i:j:p:e:xy:whuv" OPT; do
case ${OPT} in
s)
TEST_SUITE=${OPTARG}
Expand Down Expand Up @@ -240,6 +246,9 @@ while getopts ":a:s:t:d:i:j:p:e:xy:huv" OPT; do
y)
PHP_XDEBUG_PORT=${OPTARG}
;;
w)
PHPUNIT_WATCH=1
;;
h)
echo "${HELP}"
exit 0
Expand Down
6 changes: 6 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ composer test
# Run specific kind of tests
composer test:unit
composer test:func

# Run tests in watch mode
composer test:unit:watch
composer test:func:watch
```

### Run Tests Manually
Expand All @@ -63,12 +67,14 @@ vendor/bin/phpunit -c Build/Test/UnitTests.xml

# Run in Docker
Build/Test/runTests.sh
Build/Test/runTests.sh -w # Watch mode
```

Functional tests may only be run in Docker as they require more infrastructure to be set up.

```bash
Build/Test/runTests.sh -s functional
Build/Test/runTests.sh -s functional -w # Watch mode
```

To learn about available options (e.g., to select the PHP version), check the usage info:
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"solarium/solarium": "^4.2|^5.2"
},
"require-dev": {
"spatie/phpunit-watcher": "^1.23",
"typo3/cms-backend": "^9.5|^10.4",
"typo3/cms-fluid": "^9.5|^10.4",
"typo3/cms-frontend": "^9.5|^10.4",
Expand Down Expand Up @@ -76,7 +77,9 @@
"@test:func"
],
"test:unit": "phpunit -c Build/Test/UnitTests.xml",
"test:unit:watch": "phpunit-watcher watch -c Build/Test/UnitTests.xml",
"test:func": "Build/Test/runTests.sh -s functional",
"test:func:watch": "@test:func -w",
"docs:db": "./Build/Documentation/dbdocs/generate.php ./Documentation/Developers/Database.rst",
"docs:setup": "./Build/Documentation/sphinx.sh install",
"docs:serve": "./Build/Documentation/sphinx.sh serve",
Expand Down
10 changes: 10 additions & 0 deletions phpunit-watcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
watch:
directories:
- Tests/
notifications:
passingTests: false
failingTests: false
phpunit:
binaryPath: vendor/bin/phpunit
arguments: '--stop-on-failure'
timeout: 180

0 comments on commit a1b9ab4

Please sign in to comment.