downshiftorg/refute-assert

Use refuteX terminology instead of assertNotX for PHPUnit assertions, plus some extra assert/refute pairs.

2.0.0 2018-01-16 17:21 UTC

This package is not auto-updated.

Last update: 2024-11-10 05:40:32 UTC


README

PHPUnit is awesome. But remembering the inversions of the assertions is really difficult. I'm sure there's some sort of method to Sebastian's madness, but I can't figure out what it is. Take these examples:

<?php

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

Remembering where to put the Not is tough.

##Solution: Refute

RefuteAssert aliases all of the assert*Not* assertion inversions to refuteX. So, now we can type:

<?php

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

This keeps the API perfectly consistent, reads very fluently, is much easier to remember, and has the added bonus that assert and refute have the same number of characters, so it makes your test methods look cleaner. Props to Buster.js for the idea.

##Installation

Pull the package in through Composer.

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

Then, just use the RefuteAssert trait in a TestCase class that extends PHPUnit_Framework_TestCase. If you don't already have such a class, create one, otherwise just add the trait to your existing child class. Here's an example:

<?php

namespace Acme\Foo;

class MyTestCase extends \PHPUnit_Framework_Testcase {

	use \DownShift\RefuteAssert\RefuteAssert;

}