定制 adachsoft/cli-process-tester 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

adachsoft/cli-process-tester

最新稳定版本:v0.1.0

Composer 安装命令:

composer require adachsoft/cli-process-tester

包简介

Integration testing helpers for CLI applications in PHPUnit.

README 文档

README

A PHP library for writing integration tests for CLI applications using real processes via adachsoft/command-executor-lib.

Provides a fluent, readable DSL with assertions for testing CLI commands as black boxes.

Installation

composer require adachsoft/cli-process-tester

Usage

Extend CliTestCase in your tests:

<?php

use AdachSoft\CliProcessTester\CliTestCase;

class HelloCommandTest extends CliTestCase
{
    public function test_hello(): void
    {
        $this->cli('php bin/app hello --name=Arkadiusz')
            ->assertExitCode(0)
            ->assertStdoutContains('Hello Arkadiusz')
            ->assertNoStderr();
    }
}

API

CliTestCase

  • protected function cli(string $command): CliAssertion - Creates assertion builder for given command.

CliAssertion

Fluent interface with lazy execution (process runs only on first assertion, result is cached).

Configuration:

  • withInput(string $stdin): self - Provides input to STDIN.
  • withTimeout(int $seconds): self - Sets execution timeout.

Assertions (all return self for chaining):

  • assertExitCode(int $expected): self
  • assertStdoutContains(string $expected): self
  • assertStdoutEquals(string $expected): self
  • assertStderrContains(string $expected): self
  • assertNoStderr(): self
  • assertOutputMatchesRegex(string $regex): self

Examples

Test with STDIN

$this->cli('php -r "echo fread(STDIN, 1024);"')
    ->withInput("Hello from STDIN")
    ->assertStdoutContains("Hello from STDIN")
    ->assertExitCode(0);

Test with timeout

$this->cli('php -r "sleep(3);"')
    ->withTimeout(1)
    // will throw exception on timeout

Test error case

$this->cli('php -r "fwrite(STDERR, \"Error\"); exit(1);"')
    ->assertExitCode(1)
    ->assertStderrContains("Error")
    ->assertNoStderr(); // this would fail

Testing the library

composer test
# or
vendor/bin/phpunit

The library uses real proc_open through the command executor and provides stable, predictable API with no global state or magic.

Requirements

  • PHP 8.3+
  • PHPUnit 13+
  • adachsoft/command-executor-lib

License

MIT

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固