Different config per EACH test in onBoostrap

hello, trying to test live controller with minimal mocking.

basic situation using simple words:

  1. we have config for multiple adapters, which will be used by vendor-FooService
  2. in onBootstrap FooService takes this config, loops through adapters, attaches events to EventManager and so on

in result controller-action runs and everything is fine.

now about testing.
requirements:

  1. i want to test controller, which will be use SOME test implementation of adapters for FooService
  2. !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 runs onBootstrap 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

Hi @lon9man,

What I understand from your question is that you need a different configuration and a subset of modules for your test. I’m not an expert in that but I can point you to something which might help. The project which I’m sharing here was first made by the likes of Ocramius and friends. They’ve shown it how to do it. It doesn’t mean others have not done it, it is just I remember this particular example because I’m learning from it too. So without further ado here is the example code.

  1. Tell PHPUnit to look for a bootstrap file.
  2. Create a bootstrap file in which you define your specific configuration.
  3. Tell your application to use the test.config.php file for configuration.

If I missed a step then apologise in advance.

hi @ALTAMASH80

… specially prepared config before (meaning services-config, not Application-config!)?

thanks for the response, but different modules-config doesn’t help.

i need different service-config for each test-action.
IMPORTANT: this service-config consumed in onBootstrap.
but onBootstrap runs early than test-action, so i can’t substitute config inside test-action. it is too late at this point, because all logic in onBootstrap already run using basic service-config without my needed customization.

@froschdesign and @samsonasik maybe you can give some advices about first post?
thanks!