diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-16 04:01:40 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-16 04:01:40 +0900 |
| commit | fdd60a0a66890e049fea3db5c619e64e67e225df (patch) | |
| tree | cc2e03ef55af196a9e50cc1882777283190730a3 /crates/shirabe/tests/event_dispatcher/fixtures | |
| parent | 3a388b98a9aa6a14b1c7f7dc909c109cf9837800 (diff) | |
| download | php-shirabe-fdd60a0a66890e049fea3db5c619e64e67e225df.tar.gz php-shirabe-fdd60a0a66890e049fea3db5c619e64e67e225df.tar.zst php-shirabe-fdd60a0a66890e049fea3db5c619e64e67e225df.zip | |
test(event-dispatcher): run PHPUnit-class listeners in the PHP worker
The listeners of five tests are methods of
`Composer\Test\EventDispatcher\EventDispatcherTest`, which the worker
could not load because the class extends `PHPUnit\Framework\TestCase` and
phpunit is not part of the Composer runtime bundle. An empty stand-in for
that base class is enough: a parent class only has to exist at declaration
time, and method bodies and type declarations resolve lazily. The upstream
file is then required into the worker unchanged, so the listener bodies and
their `__DIR__` stay what Composer ships. The two assertions those bodies
call are the only PHPUnit members the stand-in has to implement.
`remove_listener` now compares a handle for an object the worker really
holds instead of a hand-written one, and `create_composer_instance` wires
the collaborators the autoloader-rebuild path reaches for, as the PHP
helper does.
Two tests stay ignored for a different reason: `Platform::put_env` writes
only the Shirabe process environment, while the listeners read `getenv()`
inside the long-lived worker.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/tests/event_dispatcher/fixtures')
| -rw-r--r-- | crates/shirabe/tests/event_dispatcher/fixtures/phpunit_test_case.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/crates/shirabe/tests/event_dispatcher/fixtures/phpunit_test_case.php b/crates/shirabe/tests/event_dispatcher/fixtures/phpunit_test_case.php new file mode 100644 index 00000000..72446369 --- /dev/null +++ b/crates/shirabe/tests/event_dispatcher/fixtures/phpunit_test_case.php @@ -0,0 +1,36 @@ +<?php declare(strict_types=1); + +namespace PHPUnit\Framework; + +/** + * Stands in for the base class of `Composer\Test\TestCase`, which the Composer PHP runtime + * bundle does not carry. Declaring it is all the worker needs to require the upstream + * `EventDispatcherTest` from the Composer checkout and call its listener methods. + * + * The two assertions are the only PHPUnit members those listeners use, and they report failure + * the way PHPUnit does, by throwing. + */ +class TestCase +{ + public static function assertStringContainsString(string $needle, string $haystack, string $message = ''): void + { + if (!str_contains($haystack, $needle)) { + throw new \RuntimeException($message !== '' ? $message : sprintf( + 'Failed asserting that %s contains %s.', + var_export($haystack, true), + var_export($needle, true) + )); + } + } + + public static function assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void + { + if (str_contains($haystack, $needle)) { + throw new \RuntimeException($message !== '' ? $message : sprintf( + 'Failed asserting that %s does not contain %s.', + var_export($haystack, true), + var_export($needle, true) + )); + } + } +} |
