diff --git a/Build/Test/docker-compose.yml b/Build/Test/docker-compose.yml index 3de20a1ce..b25b57ba4 100644 --- a/Build/Test/docker-compose.yml +++ b/Build/Test/docker-compose.yml @@ -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 @@ -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 " diff --git a/Build/Test/runTests.sh b/Build/Test/runTests.sh index 14770ad70..d286872e4 100755 --- a/Build/Test/runTests.sh +++ b/Build/Test/runTests.sh @@ -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}" @@ -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 @@ -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" @@ -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} @@ -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 diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 037344919..3450c595f 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -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 @@ -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: diff --git a/composer.json b/composer.json index 85a8ea38a..49ddba3ab 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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", diff --git a/phpunit-watcher.yml b/phpunit-watcher.yml new file mode 100644 index 000000000..6bf044b2c --- /dev/null +++ b/phpunit-watcher.yml @@ -0,0 +1,10 @@ +watch: + directories: + - Tests/ +notifications: + passingTests: false + failingTests: false +phpunit: + binaryPath: vendor/bin/phpunit + arguments: '--stop-on-failure' + timeout: 180