Skip to content

Commit

Permalink
Update to use compose.yml and integrate PHPUnit with Namespaces
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
Marc Wolf committed Jun 11, 2024
1 parent 4d92869 commit 3610574
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"require-dev": {
"phpunit/phpunit": "^11.2.1"
},
"autoload": {
"psr-4": {
"App\\": "src/"
}
}
}
2 changes: 1 addition & 1 deletion docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ server {

access_log /var/log/nginx/app.access.log;

root /app/public;
root /app/src/public;
index index.php;

location / {
Expand Down
2 changes: 1 addition & 1 deletion docker/php-fpm/php-overrides.ini
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
colors="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
12 changes: 12 additions & 0 deletions src/Example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
declare(strict_types=1);

namespace App;

class Example
{
public function doSomething()
{
return true;
}
}
File renamed without changes.
4 changes: 3 additions & 1 deletion tests/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use App\Example;

class ExampleTest extends TestCase
{
public function testExample()
{
$this->assertTrue(true);
$example = new Example();
$this->assertTrue($example->doSomething());
}
}

0 comments on commit 3610574

Please sign in to comment.