Files
XC_VM/tests/Unit/ExceptionHierarchyTest.php
T
Divarion-D 0d8607b17b test: add comprehensive test suite covering all P2–P4 audit phases (242 tests)
New test files:
- ModuleLoaderBootTest — 11 tests: boot lifecycle, event subscribers, BaseModule compat
- ModuleManagerMigrationsTest — 8 tests: versioned migrations, semver ordering, install/uninstall state
- ModuleStateEnumTest — 12 tests: fromRaw(), isLoadable(), ModuleManager integration
- ComposerDiscoveryTest — 7 tests: Composer 1/2 format, xcvm-module filter, deduplication, module-path
- CronProviderTest — 8 tests: BaseModule default, collectCronEntries aggregation, format validation
- ExceptionHierarchyTest — hierarchy correctness, PSR-11 NotFoundException compliance
- InterfaceContractTest — 29 reflection tests verifying all documented interface signatures
- ListensToAttributeTest — 8 tests: attribute shape, ModuleLoader integration, IS_REPEATABLE, hybrid mode
- ArchitectureTest — enforces no global \$db in modules or domain, BaseModule contract

Updated ModuleLoaderTest and ModuleLoaderPriorityTest for namespaced class
generation and resolveClassName() removal.
2026-06-15 18:07:50 +03:00

104 lines
4.1 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Verifies the exception hierarchy introduced in R3-1.
*
* These tests act as a regression guard: if any class is renamed,
* moved, or changes its parent, the test suite catches it immediately.
*/
class ExceptionHierarchyTest extends TestCase
{
// ── Base ──────────────────────────────────────────────────
public function testXcVmExceptionExtendsRuntimeException(): void {
$this->assertTrue(
is_a(XcVmException::class, RuntimeException::class, true),
'XcVmException must extend RuntimeException for backward compat'
);
}
// ── Container ─────────────────────────────────────────────
public function testContainerExceptionExtendsXcVmException(): void {
$this->assertTrue(is_a(ContainerException::class, XcVmException::class, true));
}
public function testContainerExceptionImplementsPsr11Interface(): void {
$this->assertTrue(is_a(ContainerException::class, ContainerExceptionInterface::class, true));
}
public function testCircularDependencyExceptionExtendsContainerException(): void {
$this->assertTrue(is_a(CircularDependencyException::class, ContainerException::class, true));
}
public function testServiceCreationExceptionExtendsContainerException(): void {
$this->assertTrue(is_a(ServiceCreationException::class, ContainerException::class, true));
}
public function testNotFoundExceptionExtendsContainerException(): void {
$this->assertTrue(is_a(NotFoundException::class, ContainerException::class, true));
}
public function testNotFoundExceptionImplementsPsr11Interface(): void {
$this->assertTrue(is_a(NotFoundException::class, NotFoundExceptionInterface::class, true));
}
// ── Module ────────────────────────────────────────────────
public function testModuleExceptionExtendsXcVmException(): void {
$this->assertTrue(is_a(ModuleException::class, XcVmException::class, true));
}
public function testModuleNotFoundExceptionExtendsModuleException(): void {
$this->assertTrue(is_a(ModuleNotFoundException::class, ModuleException::class, true));
}
public function testModuleCycleExceptionExtendsModuleException(): void {
$this->assertTrue(is_a(ModuleCycleException::class, ModuleException::class, true));
}
public function testModuleLoadExceptionExtendsModuleException(): void {
$this->assertTrue(is_a(ModuleLoadException::class, ModuleException::class, true));
}
public function testModuleManifestExceptionExtendsModuleException(): void {
$this->assertTrue(is_a(ModuleManifestException::class, ModuleException::class, true));
}
// ── Catchability ──────────────────────────────────────────
public function testCircularDependencyIsCatchableAsXcVmException(): void {
$caught = false;
try {
throw new CircularDependencyException('test');
} catch (XcVmException) {
$caught = true;
}
$this->assertTrue($caught, 'CircularDependencyException must be catchable as XcVmException');
}
public function testModuleCycleIsCatchableAsModuleException(): void {
$caught = false;
try {
throw new ModuleCycleException('test');
} catch (ModuleException) {
$caught = true;
}
$this->assertTrue($caught);
}
public function testModuleExceptionIsCatchableAsRuntimeException(): void {
$caught = false;
try {
throw new ModuleException('test');
} catch (RuntimeException) {
$caught = true;
}
$this->assertTrue($caught, 'ModuleException must be catchable as RuntimeException for backward compat');
}
}