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.
array|null
The customized application constructor arguments.
string|null
The customized application class name.
Clears any mocks that were defined and cleans up application class configuration.
Configure the application class to use in integration tests.
Create an application instance.
Add a mocked service to the container.
Wrap the application's container with one containing mocks.
Remove a mocked service to the container.
cleanupContainer(): void
Clears any mocks that were defined and cleans up application class configuration.
void
configApplication(string $class, array|null $constructorArgs): void
Configure the application class to use in integration tests.
string
$class The application class name.
array|null
$constructorArgs The constructor arguments for your application class.
void
createApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
Create an application instance.
Uses the configuration set in configApplication()
.
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
mockService(string $class, Closure $factory): $this
Add 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.
string
$class The class or interface you want to define.
Closure
$factory The factory function for mocked services.
$this
modifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): Cake\Core\ContainerInterface|null
Wrap 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.
Cake\Event\EventInterface
$event The event
Cake\Core\ContainerInterface
$container The container to wrap.
Cake\Core\ContainerInterface|null
removeMockService(string $class): $this
Remove a mocked service to the container.
string
$class The class or interface you want to remove.
$this
The customized application constructor arguments.
array|null
The customized application class name.
string|null
© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/4.4/trait-Cake.Core.TestSuite.ContainerStubTrait.html