Files
netslim-core/tests/Architecture/InstantiationBoundaryTest.php
2026-03-20 22:13:41 +01:00

75 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Architecture;
use Tests\Architecture\Support\ArchitectureTestCase;
final class InstantiationBoundaryTest extends ArchitectureTestCase
{
public function testApplicationServicesDoNotInstantiateUseCasesOrPoliciesDirectly(): void
{
foreach ($this->applicationServiceFiles() as $file) {
$violations = $this->collectInstantiationViolations(
$file,
self::USE_CASE_OR_POLICY_FRAGMENTS,
$this->isUseCaseOrPolicyClass(...),
);
$this->assertNoArchitectureViolations(
$violations,
$this->fileRuleMessage(self::MESSAGE_APPLICATION_SERVICE_DI_ONLY, $file),
);
}
}
public function testControllersDoNotInstantiateApplicationOrDomainDependenciesDirectly(): void
{
foreach ($this->uiControllerFiles() as $file) {
$violations = $this->collectInstantiationViolations(
$file,
self::APPLICATION_OR_DOMAIN_FRAGMENTS,
$this->isApplicationOrDomainClass(...),
);
$this->assertNoArchitectureViolations(
$violations,
$this->fileRuleMessage(self::MESSAGE_CONTROLLER_DI_ONLY, $file),
);
}
}
public function testUiLayerDoesNotInstantiateInfrastructureOrRepositoryImplementationsDirectly(): void
{
foreach ($this->uiFiles() as $file) {
$violations = $this->collectInstantiationViolations(
$file,
self::INFRASTRUCTURE_INSTANTIATION_FRAGMENTS,
$this->isInfrastructureOrRepositoryClass(...),
);
$this->assertNoArchitectureViolations(
$violations,
$this->fileRuleMessage(self::MESSAGE_UI_NO_INFRA_INSTANTIATION, $file),
);
}
}
public function testApplicationLayerDoesNotInstantiateInfrastructureOrRepositoryImplementationsDirectly(): void
{
foreach ($this->applicationFiles() as $file) {
$violations = $this->collectInstantiationViolations(
$file,
self::INFRASTRUCTURE_INSTANTIATION_FRAGMENTS,
$this->isInfrastructureOrRepositoryClass(...),
);
$this->assertNoArchitectureViolations(
$violations,
$this->fileRuleMessage(self::MESSAGE_APPLICATION_NO_INFRA_INSTANTIATION, $file),
);
}
}
}