Trait ContainerStubTrait
A set of methods used for defining container services in test cases.
This trait leverages the Application.buildContainer event
to inject the mocked services into the container that the
application uses.
Property Summary
- 
        $_appArgs protectedarray|nullThe customized application constructor arguments. 
- 
        $_appClass protectedstring|nullThe customized application class name. 
Method Summary
- 
          cleanupContainer() publicClears any mocks that were defined and cleans up application class configuration. 
- 
          configApplication() publicConfigure the application class to use in integration tests. 
- 
          createApp() protectedCreate an application instance. 
- 
          mockService() publicAdd a mocked service to the container. 
- 
          modifyContainer() publicWrap the application's container with one containing mocks. 
- 
          removeMockService() publicRemove a mocked service to the container. 
Method Detail
cleanupContainer() ¶ public
cleanupContainer(): voidClears any mocks that were defined and cleans up application class configuration.
Returns
voidconfigApplication() ¶ public
configApplication(string $class, array|null $constructorArgs): voidConfigure the application class to use in integration tests.
Parameters
- 
                string$class
- The application class name. 
- 
                array|null$constructorArgs
- The constructor arguments for your application class. 
Returns
voidcreateApp() ¶ protected
createApp(): Cake\Core\HttpApplicationInterface|Cake\Core\ConsoleApplicationInterfaceCreate an application instance.
Uses the configuration set in configApplication().
Returns
Cake\Core\HttpApplicationInterface|Cake\Core\ConsoleApplicationInterfacemockService() ¶ public
mockService(string $class, Closure $factory): $thisAdd a mocked service to the container.
When the container is created the provided classname will be mapped to the factory function. The factory function will be used to create mocked services.
Parameters
- 
                string$class
- The class or interface you want to define. 
- 
                Closure$factory
- The factory function for mocked services. 
Returns
$thismodifyContainer() ¶ public
modifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): null|Cake\Core\ContainerInterfaceWrap the application's container with one containing mocks.
If any mocked services are defined, the application's container will be replaced with one containing mocks. The original container will be set as a delegate to the mock container.
Parameters
- 
                Cake\Event\EventInterface$event
- The event 
- 
                Cake\Core\ContainerInterface$container
- The container to wrap. 
Returns
null|Cake\Core\ContainerInterfaceremoveMockService() ¶ public
removeMockService(string $class): $thisRemove a mocked service to the container.
Parameters
- 
                string$class
- The class or interface you want to remove. 
Returns
$this