dave1010/it-should 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

dave1010/it-should

Composer 安装命令:

composer require dave1010/it-should

包简介

IT: Inline Test for PHP

README 文档

README

IT: Inline Test for PHP, designed for PHP 8 5.

Install

composer require --dev dave1010/it-should

Usage

Console command

Run inline tests under one or more files/directories:

./vendor/bin/it src

Run ./vendor/bin/it help for available options.

Writing tests

Write tests inline on functions and methods with the \IT\Should annotation.

#[\IT\Should(return: 4, given: [2, 2])]
function add(int $a, int $b): int {
    return $a + $b;
}

Use the given parameter to pass the arguments that should be provided to your function or method when executing the inline test.

For methods, IT will instantiate a new object when the method is non-static (without handling constructor arguments). You can override this by providing a callable in the optional with parameter to create the system under test:

class Incrementer
{
    public function __construct(private int $step)
    {
    }

    #[\IT\Should(return: 2, given: [1], with: static function () { return new Incrementer(1); })]
    public function add(int $value): int
    {
        return $value + $this->step;
    }
}

Any callable is accepted here, whether a static closure (possible in PHP 8.5 attributes) or a class factory method.

Running tests

./vendor/bin/it src

IT will look at all the functions and classes/methods in src that have the \IT\Should attributes, then call each one, checking the output is as expected.

Development

For contributors working on this repository, the console command lives at bin/it, Not in vendor. Run composer install after cloning to generate the local vendor/autoload.php so bin/it and the bundled examples work without additional setup.

The examples and CI workflow currently run against PHP 8.5; you can mirror this locally with:

php bin/it examples

Architecture

Main interfaces:

  • Locator (finds inline tests in code, via reflection).
  • Executor (runs the tests and captures results).
  • Comparator (compares actual vs expected, producing human-friendly diffs).
  • Reporter (outputs results, exit with non-zero if any failure).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-11-21