定制 rtens/scrut 二次开发

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

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

rtens/scrut

Composer 安装命令:

composer require rtens/scrut

包简介

Light-weight test runner for PHP

README 文档

README

scrut is a full-fledged, light-weight xUnit-style test framework for PHP.

The Why

Why write another test framekwork for PHP? One could easily argue that there are already enough, and one would be right.

But apart from the fact, that writing a test framework is great fun, the main reason that lead me to doing so was that PhpUnit started to feel kinda heavy, especially as a requirement of the micro-libraries in my web application tool kit, and the alternatives didn't convince me. Other minor reasons where that I needed a more flexible testing framework for experimenting with test styles and always wanted a framework that is aligned with my work flow.

Installation

To use scrut in your project, require it with Composer

composer require "rtens/scrut"

If you would like to develop on scrut, clone it with git, download its dependencies with Composer and execute the specification with scrut itself (the bootstrapping is the major source of fun when writing test frameworks)

git clone https://github.com/rtens/scrut.git
cd scrut
composer install
vendor/bin/scrut

Usage

There are three ways to write tests with scrut which you can mix as you please.

Minimalistic

The easiest and most minimalistic way to write a test, avoiding all dependencies on scrut, is to create a class in a folder (e.g. spec) like this:

class Foo {
    function thisOnePasses() {
        assert(true);
    }
    
    function thisOneFails() {
        assert(false, "Bang");
    }
}

Note that you don't need to follow any naming convention. scrut will execute all public methods of all classes it finds in the folder you point it to. You can use the assert function or throw Exceptions to make a test fail.

If you now run vendor/bin/scrut spec you should get the following output.

.F

---- Failed ----
Foo::thisOneFails [/home/derp/scrut/spec/Foo.php:9]
    Caught E_WARNING from /home/derp/scrut/spec/Foo.php:9
    assert(): Bang failed
    
=( 1 Passed, 1 Failed

The dot means that the first test passed, the F means that the second one failed and the reason is printed below followed by a summary of the test run.

Integrated

A more integrated way is let the test class extend StaticTestSuite and use the Assert class to make assertions.

class Foo extends StaticTestSuite {
    function thisOnePasses() {
        $this->assert("1", 1);
    }
    
    function thisOneFails() {
        $this->assert->equals("1", 2);
    }
    
    function thisOneIsEmpty() {
    }
}

The output of vendor/bin/scrut spec should now be

.FI

---- Incomplete ----
Foo::thisOneIsEmpty [/home/rtens/testScrut/spec/Bar.php:12]
    No assertions made

---- Failed ----
Foo::thisOneFails [/home/rtens/testScrut/spec/Bar.php:9]
    '1' should equal 2

=( 1 Passed, 1 Incomplete, 1 Failed

Note that the empty test method results in the test being marked as "incomplete" because no assertions are made.

Dynamic

If you're not a fan of creating classes, then you might like the third way using dynamically created objects.

return (new GenericTestSuite("Foo"))
    ->test("foo", function (Assert $assert) {
        $assert("1", 1);
    });
    ->test("bar", function (Assert $assert) {
        $assert->equals(1+1, 2);
    });

which gets you

..

=D 2 Passed

Documentation

The documentation of scrut is written in the form of an executable specification. You find it in the spec folder.

Contribution

I'm looking forward to any kind of contribution including feedback about how unnecessary this project is, bugs and suggestions for missing features. Just open a new issue or check out the open issues.

rtens/scrut 适用场景与选型建议

rtens/scrut 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.07k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 05 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「BDD」 「TDD」 「test」 「test runner」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 rtens/scrut 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-11