hello, trying to test live controller with minimal mocking.
basic situation using simple words:
- we have config for multiple adapters, which will be used by vendor-
FooService
- in
onBootstrap
FooService
takes this config, loops through adapters, attaches events toEventManager
and so on
in result controller-action runs and everything is fine.
now about testing.
requirements:
- i want to test controller, which will be use SOME test implementation of adapters for
FooService
-
!IMPORTANT! EACH test-action in test-suite should use another different adapter of
FooService
----- here is the problem -----
PHPUnit before run each test-action starts laminas and it runsonBootstrap
with BASIC adapters implementation and i don’t see possible way to change this implementation to different mock-version before each test-action. it looks like race-condition.
protected function setUp(): void {
/* code before */
$this->setApplicationConfig( ArrayUtils::merge(
include __DIR__ . '/../../../../../config/application.config.php',
$configOverrides
) );
parent::setUp();
# here laminas is not started yet
$this->sm = $this->getApplicationServiceLocator();
# here laminas is started, BUT USING BASIC adapters for FooService.
# EventManager subscribed to events and other any logic in FooService in reality possible
# we can try to change something in the configureServiceManager-method (config, service),
# BUT FooService is vendor-owned.
# AFAIU such replace should include full cleanup of things like configs/events/services/...,
# which made FooService in onBootstrap-method (it looks unreal)
$this->configureServiceManager( $this->sm );
/* code after */
}
so basic question sounds like:
how to make possible that EACH test-action CAN START laminas USING specially prepared config before (meaning services-config, not Application-config!)?
in opposite now laminas starts using SAME service-config for ALL test-actions in test-suite