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.6 Strawberry API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 4.6
      • 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
      • Command
      • Exception
      • TestSuite
        • Constraint
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Filesystem
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • Shell
    • TestSuite
    • Utility
    • Validation
    • View

Trait ConsoleIntegrationTestTrait

A bundle of methods that makes testing commands and shell classes easier.

Enables you to call commands/shells with a full application context.

Namespace: Cake\Console\TestSuite

Property Summary

  • $_appArgs protected
    array|null

    The customized application constructor arguments.

  • $_appClass protected
    string|null

    The customized application class name.

  • $_err protected
    Cake\Console\TestSuite\StubConsoleOutput

    Console error output stub

  • $_exitCode protected
    int|null

    Last exit code

  • $_in protected
    Cake\Console\TestSuite\StubConsoleInput

    Console input mock

  • $_out protected
    Cake\Console\TestSuite\StubConsoleOutput

    Console output stub

  • $_useCommandRunner protected
    bool

    Whether to use the CommandRunner

Method Summary

  • assertErrorContains() public

    Asserts stderr contains expected output

  • assertErrorEmpty() public

    Asserts that stderr is empty

  • assertErrorRegExp() public

    Asserts stderr contains expected regexp

  • assertExitCode() public

    Asserts shell exited with the expected code

  • assertExitError() public

    Asserts shell exited with Command::CODE_ERROR

  • assertExitSuccess() public

    Asserts shell exited with the Command::CODE_SUCCESS

  • assertOutputContains() public

    Asserts stdout contains expected output

  • assertOutputContainsRow() protected

    Check that a row of cells exists in the output.

  • assertOutputEmpty() public

    Asserts that stdout is empty

  • assertOutputNotContains() public

    Asserts stdout does not contain expected output

  • assertOutputRegExp() public

    Asserts stdout contains expected regexp

  • cleanupConsoleTrait() public

    Cleans state to get ready for the next test

  • cleanupContainer() public

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

  • commandStringToArgs() protected

    Creates an $argv array from a command string

  • configApplication() public

    Configure the application class to use in integration tests.

  • createApp() protected

    Create an application instance.

  • exec() public

    Runs CLI integration test

  • makeRunner() protected

    Builds the appropriate command dispatcher

  • 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.

  • useCommandRunner() public

    Set this test case to use the CommandRunner rather than the legacy ShellDispatcher

Method Detail

assertErrorContains() ¶ public

assertErrorContains(string $expected, string $message = ''): void

Asserts stderr contains expected output

Parameters
string $expected

Expected output

string $message optional

Failure message

Returns
void

assertErrorEmpty() ¶ public

assertErrorEmpty(string $message = ''): void

Asserts that stderr is empty

Parameters
string $message optional

The message to output when the assertion fails.

Returns
void

assertErrorRegExp() ¶ public

assertErrorRegExp(string $pattern, string $message = ''): void

Asserts stderr contains expected regexp

Parameters
string $pattern

Expected pattern

string $message optional

Failure message

Returns
void

assertExitCode() ¶ public

assertExitCode(int $expected, string $message = ''): void

Asserts shell exited with the expected code

Parameters
int $expected

Expected exit code

string $message optional

Failure message

Returns
void

assertExitError() ¶ public

assertExitError(string $message = ''): void

Asserts shell exited with Command::CODE_ERROR

Parameters
string $message optional

Failure message

Returns
void

assertExitSuccess() ¶ public

assertExitSuccess(string $message = ''): void

Asserts shell exited with the Command::CODE_SUCCESS

Parameters
string $message optional

Failure message

Returns
void

assertOutputContains() ¶ public

assertOutputContains(string $expected, string $message = ''): void

Asserts stdout contains expected output

Parameters
string $expected

Expected output

string $message optional

Failure message

Returns
void

assertOutputContainsRow() ¶ protected

assertOutputContainsRow(array $row, string $message = ''): void

Check that a row of cells exists in the output.

Parameters
array $row

Row of cells to ensure exist in the output.

string $message optional

Failure message.

Returns
void

assertOutputEmpty() ¶ public

assertOutputEmpty(string $message = ''): void

Asserts that stdout is empty

Parameters
string $message optional

The message to output when the assertion fails.

Returns
void

assertOutputNotContains() ¶ public

assertOutputNotContains(string $expected, string $message = ''): void

Asserts stdout does not contain expected output

Parameters
string $expected

Expected output

string $message optional

Failure message

Returns
void

assertOutputRegExp() ¶ public

assertOutputRegExp(string $pattern, string $message = ''): void

Asserts stdout contains expected regexp

Parameters
string $pattern

Expected pattern

string $message optional

Failure message

Returns
void

cleanupConsoleTrait() ¶ public

cleanupConsoleTrait(): void

Cleans state to get ready for the next test

Returns
void

cleanupContainer() ¶ public

cleanupContainer(): void

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

Returns
void

commandStringToArgs() ¶ protected

commandStringToArgs(string $command): array<string>

Creates an $argv array from a command string

Parameters
string $command

Command string

Returns
array<string>

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

exec() ¶ public

exec(string $command, array $input = []): void

Runs CLI integration test

Parameters
string $command

Command to run

array $input optional

Input values to pass to an interactive shell

Returns
void
Throws
Cake\Console\TestSuite\MissingConsoleInputException

RuntimeException

makeRunner() ¶ protected

makeRunner(): Cake\Console\CommandRunner|Cake\Console\TestSuite\LegacyCommandRunner

Builds the appropriate command dispatcher

Returns
Cake\Console\CommandRunner|Cake\Console\TestSuite\LegacyCommandRunner

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

useCommandRunner() ¶ public

useCommandRunner(): void

Set this test case to use the CommandRunner rather than the legacy ShellDispatcher

Returns
void

Property Detail

$_appArgs ¶ protected

The customized application constructor arguments.

Type
array|null

$_appClass ¶ protected

The customized application class name.

Type
string|null

$_err ¶ protected

Console error output stub

Type
Cake\Console\TestSuite\StubConsoleOutput

$_exitCode ¶ protected

Last exit code

Type
int|null

$_in ¶ protected

Console input mock

Type
Cake\Console\TestSuite\StubConsoleInput

$_out ¶ protected

Console output stub

Type
Cake\Console\TestSuite\StubConsoleOutput

$_useCommandRunner ¶ protected

Whether to use the CommandRunner

Type
bool
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