From 36105747ffd3bd029660eb992ca5c2278f72022b Mon Sep 17 00:00:00 2001 From: Marc Wolf Date: Tue, 11 Jun 2024 16:31:11 +0200 Subject: [PATCH] Update to use compose.yml and integrate PHPUnit with Namespaces - Rename docker-compose.yml to compose.yml - Add PHPUnit 11.2.1 to composer.json - Add phpunit.xml for PHPUnit configuration - Update README.md with setup instructions for Docker Compose and PHPUnit - Ensure .gitignore includes vendor directory - Adjust GitHub Actions workflow to use compose.yml - Add Example class and corresponding PHPUnit test with App namespace - Update composer.json to include PSR-4 autoloading for App namespace - Ensure Xdebug is configured correctly for code coverage --- .github/workflows/ci.yml | 2 +- compose.yml | 2 +- composer.json | 5 +++++ docker/nginx/nginx.conf | 2 +- docker/php-fpm/php-overrides.ini | 2 +- phpunit.xml | 18 ++++++++++++++++++ src/Example.php | 12 ++++++++++++ {public => src/public}/index.php | 0 tests/ExampleTest.php | 4 +++- 9 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 phpunit.xml create mode 100644 src/Example.php rename {public => src/public}/index.php (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6292b9d..523fafd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: Run PHPUnit tests run: | - docker compose exec -T php-fpm ./vendor/bin/phpunit tests + docker compose exec -T php-fpm ./vendor/bin/phpunit --coverage-text --testdox tests - name: Test Redis run: | diff --git a/compose.yml b/compose.yml index 1b0036c..0e50fc5 100644 --- a/compose.yml +++ b/compose.yml @@ -21,7 +21,7 @@ services: - ".:/app" - "./docker/php-fpm/php-overrides.ini:/usr/local/etc/php/conf.d/php-overrides.ini" environment: - XDEBUG_MODE: "debug" + XDEBUG_MODE: "coverage" redis: image: "redis:7.2.5-alpine" diff --git a/composer.json b/composer.json index 65a9d51..8caf422 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,10 @@ { "require-dev": { "phpunit/phpunit": "^11.2.1" + }, + "autoload": { + "psr-4": { + "App\\": "src/" + } } } diff --git a/docker/nginx/nginx.conf b/docker/nginx/nginx.conf index cd94e2b..b033c4a 100644 --- a/docker/nginx/nginx.conf +++ b/docker/nginx/nginx.conf @@ -6,7 +6,7 @@ server { access_log /var/log/nginx/app.access.log; - root /app/public; + root /app/src/public; index index.php; location / { diff --git a/docker/php-fpm/php-overrides.ini b/docker/php-fpm/php-overrides.ini index 3392351..62e61d3 100644 --- a/docker/php-fpm/php-overrides.ini +++ b/docker/php-fpm/php-overrides.ini @@ -1,6 +1,6 @@ upload_max_filesize=100M post_max_size=100M -xdebug.mode=debug +xdebug.mode=coverage xdebug.start_with_request=yes xdebug.client_port=9003 xdebug.client_host=host.docker.internal diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..e069076 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + tests + + + + + src + + + diff --git a/src/Example.php b/src/Example.php new file mode 100644 index 0000000..27c716e --- /dev/null +++ b/src/Example.php @@ -0,0 +1,12 @@ +assertTrue(true); + $example = new Example(); + $this->assertTrue($example->doSomething()); } }