netrivet/refute-assert

此包已被废弃,不再维护。作者建议使用 downshiftorg/refute-assert 包。

在 PHPUnit 断言中,使用 refuteX 术语代替 assertNotX,并提供一些额外的 assert/refute 对。

2.0.0 2018-01-16 17:21 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:45:19 UTC


README

PHPUnit 非常棒。但记住 断言的逆序 真的很困难。我确信Sebastian的疯狂中一定有一些方法,但我不知道是什么。看看这些例子

<?php

$this->assertNotContainsOnly();
$this->assertClassNotHasStaticAttribute();
$this->assertStringEndsNotWith();

记住在哪里放置 Not 真的很困难。

##解决方案:Refute

RefuteAssert 将所有的 assert*Not* 断言逆序别名到 refuteX。所以现在我们可以输入

<?php

$this->refuteContainsOnly();
$this->refuteClassHasStaticAttribute();
$this->refuteStringEndsWith();

这保持了API的完美一致性,读起来非常流畅,更容易记住,而且有一个额外的优点是 assertrefute 的字符数相同,这使得你的测试方法看起来更整洁。感谢 Buster.js 的想法。

##安装

通过 Composer 拉取包。

{
    "require": {
        "downshiftorg/refute-assert": "0.1.*"
    }
}

然后,只需在扩展 PHPUnit_Framework_TestCase 的 TestCase 类中使用 RefuteAssert 特性。如果你还没有这样的类,创建一个,否则只需将特性添加到现有的子类中。以下是一个示例

<?php

namespace Acme\Foo;

class MyTestCase extends \PHPUnit_Framework_Testcase {

	use \DownShift\RefuteAssert\RefuteAssert;

}