From 6d92b61f8d3fc41c8cebd322758fcd57486ff764 Mon Sep 17 00:00:00 2001 From: Alexander Kellner Date: Fri, 20 Dec 2024 11:06:29 +0100 Subject: [PATCH] [TASK] Add codeception test setup --- .env | 10 +++++ .gitignore | 2 + .project/docker/php/Dockerfile | 11 ++++++ Makefile | 22 +++++++++++ .../Acceptance/_support/AcceptanceTester.php | 25 +++++++++++++ Tests/Acceptance/acceptance.suite.yml | 18 +++++++++ Tests/Acceptance/acceptance/FirstCest.php | 14 +++++++ codeception.yml | 10 +++++ composer.json | 31 +++++++++------- docker-compose.selenium.yml | 37 +++++++++++++++++++ 10 files changed, 167 insertions(+), 13 deletions(-) create mode 100755 Tests/Acceptance/_support/AcceptanceTester.php create mode 100644 Tests/Acceptance/acceptance.suite.yml create mode 100644 Tests/Acceptance/acceptance/FirstCest.php create mode 100644 codeception.yml create mode 100644 docker-compose.selenium.yml diff --git a/.env b/.env index e3c1acce..2d893618 100644 --- a/.env +++ b/.env @@ -35,3 +35,13 @@ TYPO3_INSTALL_ADMIN_PASSWORD=Password123! TYPO3_INSTALL_SITE_NAME="Lux" TYPO3_INSTALL_SITE_SETUP_TYPE=no TYPO3_INSTALL_WEB_SERVER_CONFIG=apache + +# CodeCeption +SELENIARM_PORT_4442=61000 +SELENIARM_PORT_4443=61001 +SELENIARM_PORT_4444=61002 +PORT_CHROME=61003 +PORT_FIREFOX=61004 +VNC_PORT_CHROME=61005 +VNC_PORT_FIREFOX=61006 +TEST_URL='https://local.lux.de' diff --git a/.gitignore b/.gitignore index 958cfe8b..5a50f162 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ var/ /config/ /.phpunit.cache/ /.env.local +/Tests/Acceptance/_output/* +/Tests/Acceptance/_support/_generated/ diff --git a/.project/docker/php/Dockerfile b/.project/docker/php/Dockerfile index f94b05da..7eddf3ec 100644 --- a/.project/docker/php/Dockerfile +++ b/.project/docker/php/Dockerfile @@ -1,3 +1,14 @@ FROM in2code/php-dev:8.2-fpm COPY zz_xdebug.ini /usr/local/etc/php/conf.d/zz_xdebug.ini + +USER root + +# Install CURL extension +RUN apt-get update && apt-get install -y \ + libcurl4-openssl-dev \ + && docker-php-ext-install curl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +USER www-data diff --git a/Makefile b/Makefile index aff33b8a..16e69e52 100644 --- a/Makefile +++ b/Makefile @@ -212,6 +212,28 @@ ifeq ($(shell uname -s), Darwin) docker-compose exec -u root php chown -R app:app /app/$(TYPO3_CACHE_DIR)/; endif +## Run acceptance tests +test-acceptance: .selenium-start + echo "$(EMOJI_robot) Running acceptance tests" + docker-compose exec php bash -c "\ + sleep 2 && \ + ./.Build/bin/codecept clean && \ + ./.Build/bin/codecept build && \ + ./.Build/bin/codecept run acceptance" + echo "$(EMOJI_broom) Cleaning up selenium services"; \ + make .selenium-stop; \ + exit $${EXIT_CODE:-0} + +## Start Selenium services for testing +.selenium-start: + echo "$(EMOJI_rocket) Starting Selenium services for testing" + docker compose -f docker-compose.yml -f docker-compose.selenium.yml up -d seleniarm-hub chrome firefox + +## Stop Selenium services for testing +.selenium-stop: + echo "$(EMOJI_stop) Stopping Selenium services" + docker compose -f docker-compose.selenium.yml stop seleniarm-hub chrome firefox + include .env # SETTINGS diff --git a/Tests/Acceptance/_support/AcceptanceTester.php b/Tests/Acceptance/_support/AcceptanceTester.php new file mode 100755 index 00000000..cf989fd8 --- /dev/null +++ b/Tests/Acceptance/_support/AcceptanceTester.php @@ -0,0 +1,25 @@ +amOnPage('/'); + $I->see('Marketing'); + } +} diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 00000000..6c16c1db --- /dev/null +++ b/codeception.yml @@ -0,0 +1,10 @@ +namespace: In2code\Lux\Tests +paths: + tests: Tests/Acceptance + output: Tests/Acceptance/_output + data: Tests/Acceptance/_data + support: Tests/Acceptance/_support + envs: Tests/Acceptance/_envs +extensions: + enabled: + - Codeception\Extension\RunFailed diff --git a/composer.json b/composer.json index ae840b68..848e8ab2 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,23 @@ "typo3/cms-dashboard": "*" }, "require-dev": { + "codeception/codeception": "^5.1", + "codeception/module-asserts": "^3.0", + "codeception/module-phpbrowser": "^3.0", + "codeception/module-webdriver": "^4.0", + "friendsofphp/php-cs-fixer": "^3.10", + "georgringer/news": "^12.0", + "helmich/typo3-typoscript-lint": "^3.1", + "helhum/typo3-console": "^8.2", + "mikey179/vfsstream": "^1.6", + "phpmd/phpmd": "^2.8", + "symfony/config": ">6.2.0", + "squizlabs/php_codesniffer": "^3.5", + "typo3/cms-adminpanel": "^13.3", + "typo3/cms-belog": "^13.3", + "typo3/cms-beuser": "^13.3", "typo3/cms-core": "^13.3", + "typo3/cms-dashboard": "^13.3", "typo3/cms-extbase": "^13.3", "typo3/cms-extensionmanager": "^13.3", "typo3/cms-felogin": "^13.3", @@ -49,26 +65,14 @@ "typo3/cms-frontend": "^13.3", "typo3/cms-info": "^13.3", "typo3/cms-install": "^13.3", + "typo3/cms-lowlevel": "^13.3", "typo3/cms-recordlist": "^13.3", "typo3/cms-rte-ckeditor": "^13.3", "typo3/cms-scheduler": "^13.3", "typo3/cms-setup": "^13.3", "typo3/cms-t3editor": "^13.3", "typo3/cms-tstemplate": "^13.3", - "typo3/cms-lowlevel": "^13.3", - "typo3/cms-adminpanel": "^13.3", - "typo3/cms-belog": "^13.3", - "typo3/cms-beuser": "^13.3", - "typo3/cms-dashboard": "^13.3", "typo3/testing-framework": "^8.2", - "symfony/config": ">6.2.0", - "mikey179/vfsstream": "^1.6", - "squizlabs/php_codesniffer": "^3.5", - "phpmd/phpmd": "^2.8", - "friendsofphp/php-cs-fixer": "^3.10", - "helmich/typo3-typoscript-lint": "^3.1", - "helhum/typo3-console": "^8.2", - "georgringer/news": "^12.0", "typo3/cms-indexed-search": "^13.4", "typo3/cms-form": "^13.4" }, @@ -100,6 +104,7 @@ }, "extra": { "typo3/cms": { + "app-dir": ".Build", "cms-package-dir": "{$vendor-dir}/typo3/cms", "web-dir": ".Build/public", "extension-key": "lux", diff --git a/docker-compose.selenium.yml b/docker-compose.selenium.yml new file mode 100644 index 00000000..389b9404 --- /dev/null +++ b/docker-compose.selenium.yml @@ -0,0 +1,37 @@ +version: "3.7" + +services: + chrome: + image: seleniarm/node-chromium:4.1.2-20220227 + volumes: + - /dev/shm:/dev/shm + depends_on: + - seleniarm-hub + environment: + - SE_EVENT_BUS_HOST=seleniarm-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + ports: + - ${PORT_CHROME}:5900 + - ${VNC_PORT_CHROME}:5900 # for vnc + + firefox: + image: seleniarm/node-firefox:4.1.2-20220227 + volumes: + - /dev/shm:/dev/shm + depends_on: + - seleniarm-hub + environment: + - SE_EVENT_BUS_HOST=seleniarm-hub + - SE_EVENT_BUS_PUBLISH_PORT=4442 + - SE_EVENT_BUS_SUBSCRIBE_PORT=4443 + ports: + - ${PORT_FIREFOX}:5900 + - ${VNC_PORT_FIREFOX}:5900 # for vnc + + seleniarm-hub: + image: seleniarm/hub:4.1.2-20220227 + ports: + - ${SELENIARM_PORT_4442}:4442 + - ${SELENIARM_PORT_4443}:4443 + - ${SELENIARM_PORT_4444}:4444