特性 ConsoleIntegrationTestTrait
一组简化测试命令和 shell 类的方法。
使您能够在完整应用程序上下文中调用命令/shell。
属性摘要
-
$_appArgs protected
array|null自定义的应用程序构造函数参数。
-
$_appClass protected
string|null自定义的应用程序类名。
-
$_err protected
Cake\Console\TestSuite\StubConsoleOutput|null控制台错误输出存根
-
$_exitCode protected
int|null最后一个退出代码
-
$_in protected
Cake\Console\TestSuite\StubConsoleInput|null控制台输入模拟
-
$_out protected
Cake\Console\TestSuite\StubConsoleOutput|null控制台输出存根
方法摘要
-
assertErrorContains() public
断言
stderr包含预期输出 -
assertErrorEmpty() public
断言
stderr为空 -
assertErrorRegExp() public
断言
stderr包含预期正则表达式 -
assertExitCode() public
断言 shell 以预期代码退出
-
assertExitError() public
断言 shell 以 Command::CODE_ERROR 退出
-
assertExitSuccess() public
断言 shell 以 Command::CODE_SUCCESS 退出
-
assertOutputContains() public
断言
stdout包含预期输出 -
assertOutputContainsRow() protected
检查输出中是否存在一行单元格。
-
assertOutputEmpty() public
断言
stdout为空 -
assertOutputNotContains() public
断言
stdout不包含预期输出 -
assertOutputRegExp() public
断言
stdout包含预期正则表达式 -
cleanupConsoleTrait() public
清理状态以准备下一个测试
-
cleanupContainer() public
清除任何已定义的模拟并清理应用程序类配置。
-
commandStringToArgs() protected
从命令字符串创建 $argv 数组
-
configApplication() public
配置在集成测试中使用的应用程序类。
-
createApp() protected
创建应用程序实例。
-
exec() public
运行 CLI 集成测试
-
makeRunner() protected
构建适当的命令调度器
-
mockService() public
向容器添加模拟服务。
-
modifyContainer() public
用包含模拟的容器包装应用程序的容器。
-
removeMockService() public
从容器中删除模拟服务。
方法详情
assertErrorContains() ¶ public
assertErrorContains(string $expected, string $message = ''): void
断言 stderr 包含预期输出
参数
-
string$expected 预期输出
-
string$message optional 失败消息
返回值
voidassertErrorEmpty() ¶ public
assertErrorEmpty(string $message = ''): void
断言 stderr 为空
参数
-
string$message optional 断言失败时输出的消息。
返回值
voidassertErrorRegExp() ¶ public
assertErrorRegExp(string $pattern, string $message = ''): void
断言 stderr 包含预期正则表达式
参数
-
string$pattern 预期模式
-
string$message optional 失败消息
返回值
voidassertExitCode() ¶ public
assertExitCode(int $expected, string $message = ''): void
断言 shell 以预期代码退出
参数
-
int$expected 预期退出代码
-
string$message optional 失败消息
返回值
voidassertExitError() ¶ public
assertExitError(string $message = ''): void
断言 shell 以 Command::CODE_ERROR 退出
参数
-
string$message optional 失败消息
返回值
voidassertExitSuccess() ¶ public
assertExitSuccess(string $message = ''): void
断言 shell 以 Command::CODE_SUCCESS 退出
参数
-
string$message optional 失败消息
返回值
voidassertOutputContains() ¶ public
assertOutputContains(string $expected, string $message = ''): void
断言 stdout 包含预期输出
参数
-
string$expected 预期输出
-
string$message optional 失败消息
返回值
voidassertOutputContainsRow() ¶ protected
assertOutputContainsRow(array $row, string $message = ''): void
检查输出中是否存在一行单元格。
参数
-
array$row 确保在输出中存在的单元格行。
-
string$message optional 失败消息。
返回值
voidassertOutputEmpty() ¶ public
assertOutputEmpty(string $message = ''): void
断言 stdout 为空
参数
-
string$message optional 断言失败时输出的消息。
返回值
voidassertOutputNotContains() ¶ public
assertOutputNotContains(string $expected, string $message = ''): void
断言 stdout 不包含预期输出
参数
-
string$expected 预期输出
-
string$message optional 失败消息
返回值
voidassertOutputRegExp() ¶ public
assertOutputRegExp(string $pattern, string $message = ''): void
断言 stdout 包含预期正则表达式
参数
-
string$pattern 预期模式
-
string$message optional 失败消息
返回值
voidcommandStringToArgs() ¶ protected
commandStringToArgs(string $command): list<string>
从命令字符串创建 $argv 数组
参数
-
string$command 命令字符串
返回值
list<string>configApplication() ¶ public
configApplication(string $class, array|null $constructorArgs): void
配置在集成测试中使用的应用程序类。
参数
-
string$class 应用程序类名。
-
array|null$constructorArgs 应用程序类的构造函数参数。
返回值
voidcreateApp() ¶ protected
createApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface
创建应用程序实例。
使用 configApplication() 中设置的配置。
返回值
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterfaceexec() ¶ public
exec(string $command, array $input = []): void
运行 CLI 集成测试
参数
-
string$command 要运行的命令
-
array$input optional 传递给交互式 shell 的输入值
返回值
void抛出异常
Cake\Console\TestSuite\MissingConsoleInputExceptionInvalidArgumentExceptionmakeRunner() ¶ protected
makeRunner(): Cake\Console\CommandRunner
构建适当的命令调度器
返回值
Cake\Console\CommandRunnermockService() ¶ public
mockService(string $class, Closure $factory): $this
向容器添加模拟服务。
当容器创建时,提供的类名将映射到工厂函数。工厂函数将用于创建模拟服务。
参数
-
string$class 要定义的类或接口。
-
Closure$factory 模拟服务的工厂函数。
返回值
$thismodifyContainer() ¶ public
modifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): void
用包含模拟的容器包装应用程序的容器。
如果定义了任何模拟服务,应用程序的容器将被替换为包含模拟的容器。原始容器将被设置为模拟容器的委托。
参数
-
Cake\Event\EventInterface$event 事件
-
Cake\Core\ContainerInterface$container 要包装的容器。
返回值
voidremoveMockService() ¶ public
removeMockService(string $class): $this
从容器中删除模拟服务。
参数
-
string$class 要删除的类或接口。
返回值
$this