CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 4.4 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.4
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Auth
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
      • Configure
      • Exception
      • Retry
      • TestSuite
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

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.

Namespace: Cake\Core\TestSuite

Property Summary

  • $_appArgs protected
    array|null

    The customized application constructor arguments.

  • $_appClass protected
    string|null

    The customized application class name.

Method Summary

  • cleanupContainer() public

    Clears any mocks that were defined and cleans up application class configuration.

  • configApplication() public

    Configure the application class to use in integration tests.

  • createApp() protected

    Create an application instance.

  • mockService() public

    Add a mocked service to the container.

  • modifyContainer() public

    Wrap the application's container with one containing mocks.

  • removeMockService() public

    Remove a mocked service to the container.

Method Detail

cleanupContainer() ¶ public

cleanupContainer(): void

Clears any mocks that were defined and cleans up application class configuration.

Returns
void

configApplication() ¶ public

configApplication(string $class, array|null $constructorArgs): void

Configure 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
void

createApp() ¶ protected

createApp(): Cake\Core\HttpApplicationInterface|Cake\Core\ConsoleApplicationInterface

Create an application instance.

Uses the configuration set in configApplication().

Returns
Cake\Core\HttpApplicationInterface|Cake\Core\ConsoleApplicationInterface

mockService() ¶ public

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.

Parameters
string $class

The class or interface you want to define.

Closure $factory

The factory function for mocked services.

Returns
$this

modifyContainer() ¶ public

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.

Parameters
Cake\Event\EventInterface $event

The event

Cake\Core\ContainerInterface $container

The container to wrap.

Returns
Cake\Core\ContainerInterface|null

removeMockService() ¶ public

removeMockService(string $class): $this

Remove a mocked service to the container.

Parameters
string $class

The class or interface you want to remove.

Returns
$this

Property Detail

$_appArgs ¶ protected

The customized application constructor arguments.

Type
array|null

$_appClass ¶ protected

The customized application class name.

Type
string|null
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs