hershel-theodore-layton/test-chain 问题修复 & 功能扩展

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

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

hershel-theodore-layton/test-chain

Composer 安装命令:

composer require hershel-theodore-layton/test-chain

包简介

Inferred types for your tests, just append.

README 文档

README

Inferred types for your tests, just append.

This package was written to replace HackTest.

This package is enjoyed best with an assertion library, such as expect.

Usage

Create a tests/ directory at the root of your project (next to vendor/). This package ships with a bin/test-chain script. Do not pass any command line arguments to this script.

This script will create a json file at tests/test-chain/config.json. The defaults will likely suffice, but you can change the configuration to your liking. The tests/run.hack file template is meant for you to customize, and allows you to do setup work before running the tests.

Let's add your first test. Create tests/math_test.hack with this content.

namespace YourNamespace;

use namespace HTL\TestChain;

<<TestChain\Discover>>
function my_test(TestChain\Chain $chain)[]: TestChain\Chain {
  return $chain->group(__FUNCTION__)
    ->test('addition', () ==> {
      throw new \RuntimeException('not implemented');
    });
}

You can discover your tests using vendor/bin/test-chain. You can run your tests using hhvm tests/run.hack. You can combine these steps with vendor/bin/test-chain --run. You should see this output.

(0001 / 0001) Fail: YourNamespace\my_test (1 tests)
  - addition: not implemented
---

Tests failed!

It is common to want to execute the same test with multiple values. This is called a data-provider test. Here is an example of a such a test:

<<TestChain\Discover>>
function passing_test(TestChain\Chain $chain)[]: TestChain\Chain {
  return $chain->group(__FUNCTION__)
    ->testWith3Params(
      'division',
      () ==> vec[
        tuple(8, 2, 4),
        tuple(12, 3, 4),
      ],
      ($a, $b, $expected) ==> {
        if ($a / $b !== $expected) {
          throw new \LogicException('math broke');
        }
      },
    );
}

Running in CI

When running in CI, you don't want to suddenly discover new tests. If that were allowed, the tests you see in git and what runs in CI wouldn't be the same. By passing --ci to vendor/bin/test-chain, you assert the chain.hack file was correct and invoke the tests in the same way as with --run.

Performance on small test suites

By default hhvm will try to jit your tests as you run them, unless overriden in your global hhvm configuration. This is not helpful on most small test suites. vendor/bin/test-chain-no-jit behaves exactly like vendor/bin/test-chain, but invokes hhvm without the jit. This can shave of a second of your test execution time. It will run a test suite with a handful of fast tests in 0.5 seconds instead of 1.5 seconds.

If you want to run your tests in 0.05 seconds, you can host your tests as a web server. hhvm -m server -p <%port%> and curl http://localhost:<%port%>/tests/test-chain/run.hack. This will not crawl your tests directory for new test functions. Chained tests on existing functions will be found and run, but new <<TestChain\Discover>> functions must be explicitly crawled for with the CLI script.

Upgrades and compatibility

When the codegen for chain.hack changes, all invocations with --ci will fail. Running without --ci will regenerate this file and further invocations of --ci will not fail. If a change to chain.hack makes the call in run.hack you can regen it with --update. Your custom change will have to be reapplied. If none of that works, --reset will treat your project as a brand new project, keeping the license comment and the namespace the same for convenience.

These breakages in codegen will not require a major version bump.

hershel-theodore-layton/test-chain 适用场景与选型建议

hershel-theodore-layton/test-chain 是一款 基于 Hack 开发的 Composer 扩展包,目前已累计 5.35k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hershel-theodore-layton/test-chain 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hershel-theodore-layton/test-chain 我们能提供哪些服务?
定制开发 / 二次开发

基于 hershel-theodore-layton/test-chain 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: Hack

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-18