From b66a658a6c6c6075c47800118021bb34cfb0f299 Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Sun, 14 Jun 2026 02:44:23 +0200 Subject: [PATCH 1/2] :white_check_mark: test: Job/JobMessage Unit-Tests + CLI-Compose-Runner + GitHub-Action [*] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Unit-Tests (PHPUnit 12) für die öffentlichen Kern-Klassen, plus je Paket ein CLI-only docker-compose-Runner (composer install + vendor/bin/phpunit), ein GitHub-Actions-Workflow und .gitignore. phpunit ^12 in require-dev. Außerdem: fehlende Laufzeit-Abhängigkeit symfony/uid zu require ergänzt (Job-Entity nutzt Symfony\Component\Uid\Uuid; vom Test aufgedeckt). Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/tests.yml | 24 ++++++++++ .gitignore | 4 ++ composer.json | 4 ++ docker-compose.yml | 15 +++++++ phpunit.dist.xml | 18 ++++++++ tests/Entity/JobTest.php | 75 ++++++++++++++++++++++++++++++++ tests/Message/JobMessageTest.php | 26 +++++++++++ 7 files changed, 166 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 phpunit.dist.xml create mode 100644 tests/Entity/JobTest.php create mode 100644 tests/Message/JobMessageTest.php diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..afd9a6f --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,24 @@ +# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC +name: Tests + +on: + push: + branches: [main, master, "feature/**"] + pull_request: + +jobs: + phpunit: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: ["8.2", "8.4"] + name: PHPUnit (PHP ${{ matrix.php }}) + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - run: composer install --no-interaction --no-progress + - run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cff2af8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC +/vendor/ +/composer.lock +/.phpunit.cache/ diff --git a/composer.json b/composer.json index 07d5514..fe0e734 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,13 @@ "php": ">=8.2", "symfony/framework-bundle": "^7.0", "symfony/messenger": "^7.0", + "symfony/uid": "^7.0", "doctrine/orm": "^3.0", "doctrine/doctrine-bundle": "^2.0" }, + "require-dev": { + "phpunit/phpunit": "^12.0" + }, "autoload": { "psr-4": { "Dmstr\\SymfonyJobQueue\\": "src/" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8086794 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC +# CLI-only test runner for this bundle — no MySQL/FPM required. +# Usage (on host): +# docker compose run --rm php +# Runs `composer install` then PHPUnit against tests/. +services: + php: + build: + dockerfile_inline: | + FROM php:8.4-cli-alpine + COPY --from=composer:2 /usr/bin/composer /usr/bin/composer + working_dir: /repo + volumes: + - .:/repo + command: sh -c "composer install --no-interaction --no-progress && vendor/bin/phpunit" diff --git a/phpunit.dist.xml b/phpunit.dist.xml new file mode 100644 index 0000000..9dc4142 --- /dev/null +++ b/phpunit.dist.xml @@ -0,0 +1,18 @@ + + + + + + tests + + + + + src + + + diff --git a/tests/Entity/JobTest.php b/tests/Entity/JobTest.php new file mode 100644 index 0000000..85f610b --- /dev/null +++ b/tests/Entity/JobTest.php @@ -0,0 +1,75 @@ +getId()), 'id must be a valid UUID'); + self::assertSame('pending', $job->getStatus()); + self::assertSame(0, $job->getProgress()); + self::assertSame([], $job->getInputData()); + self::assertNull($job->getResultData()); + self::assertNull($job->getErrorMessage()); + self::assertNull($job->getStartedAt()); + self::assertNull($job->getCompletedAt()); + self::assertInstanceOf(\DateTimeImmutable::class, $job->getCreatedAt()); + self::assertInstanceOf(\DateTimeImmutable::class, $job->getUpdatedAt()); + } + + public function testEachJobGetsAUniqueId(): void + { + self::assertNotSame((new Job())->getId(), (new Job())->getId()); + } + + public function testFluentSettersUpdateState(): void + { + $job = new Job(); + $started = new \DateTimeImmutable('2026-01-01 10:00:00'); + $completed = new \DateTimeImmutable('2026-01-01 10:05:00'); + + $result = $job + ->setType('ref_project_scan') + ->setStatus('completed') + ->setInputData(['apiConfiguration' => ['uuid' => '5302d197']]) + ->setResultData(['imported' => 42]) + ->setErrorMessage('none') + ->setProgress(100) + ->setStartedAt($started) + ->setCompletedAt($completed); + + self::assertSame($job, $result, 'setters must be fluent'); + self::assertSame('ref_project_scan', $job->getType()); + self::assertSame('completed', $job->getStatus()); + self::assertSame(['apiConfiguration' => ['uuid' => '5302d197']], $job->getInputData()); + self::assertSame(['imported' => 42], $job->getResultData()); + self::assertSame('none', $job->getErrorMessage()); + self::assertSame(100, $job->getProgress()); + self::assertSame($started, $job->getStartedAt()); + self::assertSame($completed, $job->getCompletedAt()); + } + + public function testOnPreUpdateRefreshesUpdatedAt(): void + { + $job = new Job(); + $job->onPreUpdate(); + + self::assertInstanceOf(\DateTimeImmutable::class, $job->getUpdatedAt()); + self::assertGreaterThanOrEqual($job->getCreatedAt(), $job->getUpdatedAt()); + } +} diff --git a/tests/Message/JobMessageTest.php b/tests/Message/JobMessageTest.php new file mode 100644 index 0000000..e80687a --- /dev/null +++ b/tests/Message/JobMessageTest.php @@ -0,0 +1,26 @@ +getJobId()); + } + + public function testDistinctMessagesKeepTheirOwnId(): void + { + self::assertSame('a', (new JobMessage('a'))->getJobId()); + self::assertSame('b', (new JobMessage('b'))->getJobId()); + } +} From 67389bfa0c41b199b94bcdea3227e61f72137a8d Mon Sep 17 00:00:00 2001 From: Tobias Munk Date: Sun, 14 Jun 2026 03:28:23 +0200 Subject: [PATCH 2/2] =?UTF-8?q?:green=5Fheart:=20ci:=20PHP-Matrix=20auf=20?= =?UTF-8?q?8.3/8.4=20(phpunit=20^12=20ben=C3=B6tigt=20PHP=20>=3D8.3)=20[*]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 8.2 fiel raus: PHPUnit 12 verlangt PHP >=8.3, daher schlug composer install im 8.2-Job fehl. Runtime-Constraint des Pakets (>=8.2) bleibt unverändert. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index afd9a6f..2cd720b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - php: ["8.2", "8.4"] + php: ["8.3", "8.4"] name: PHPUnit (PHP ${{ matrix.php }}) steps: - uses: actions/checkout@v4