Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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.3", "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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC
/vendor/
/composer.lock
/.phpunit.cache/
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"dmstr/api-platform-utils-bundle": "*",
"dmstr/openapi-json-schema-bundle": "*"
},
"require-dev": {
"phpunit/phpunit": "^12.0"
},
"autoload": {
"psr-4": {
"Dmstr\\ApiConfiguration\\": "src/"
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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"
18 changes: 18 additions & 0 deletions phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
82 changes: 82 additions & 0 deletions tests/Service/ApiExtensionRegistryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
// file generated with AI assistance: Claude Code - 2026-06-13 23:14:54 UTC

declare(strict_types=1);

namespace Dmstr\ApiConfiguration\Tests\Service;

use Dmstr\ApiConfiguration\Extension\ApiExtensionInterface;
use Dmstr\ApiConfiguration\Service\ApiExtensionRegistry;
use PHPUnit\Framework\TestCase;

/**
* Unit tests for {@see ApiExtensionRegistry} — the in-memory map of pluggable
* API extensions keyed by their {@see ApiExtensionInterface::getName()}.
*/
final class ApiExtensionRegistryTest extends TestCase
{
public function testRegisterAndGet(): void
{
$registry = new ApiExtensionRegistry();
$github = $this->extension('github');

$registry->register($github);

self::assertSame($github, $registry->get('github'));
}

public function testGetUnknownReturnsNull(): void
{
self::assertNull((new ApiExtensionRegistry())->get('does-not-exist'));
}

public function testHasReflectsRegistration(): void
{
$registry = new ApiExtensionRegistry();
self::assertFalse($registry->has('gitlab'));

$registry->register($this->extension('gitlab'));
self::assertTrue($registry->has('gitlab'));
}

public function testAllReturnsNameKeyedMap(): void
{
$registry = new ApiExtensionRegistry();
$github = $this->extension('github');
$gitlab = $this->extension('gitlab');
$registry->register($github);
$registry->register($gitlab);

self::assertSame(['github' => $github, 'gitlab' => $gitlab], $registry->all());
}

public function testGetNamesListsRegisteredKeys(): void
{
$registry = new ApiExtensionRegistry();
$registry->register($this->extension('github'));
$registry->register($this->extension('basecamp4'));

self::assertSame(['github', 'basecamp4'], $registry->getNames());
}

public function testRegisteringSameNameOverwrites(): void
{
$registry = new ApiExtensionRegistry();
$first = $this->extension('github');
$second = $this->extension('github');

$registry->register($first);
$registry->register($second);

self::assertSame($second, $registry->get('github'));
self::assertCount(1, $registry->all());
}

private function extension(string $name): ApiExtensionInterface
{
$extension = $this->createStub(ApiExtensionInterface::class);
$extension->method('getName')->willReturn($name);

return $extension;
}
}
Loading