marcin-orlowski/phpunit-extra-asserts

Extra asserts and helpers to make your unit testing easier.

5.3.0 2024-04-23 10:10 UTC

This package is auto-updated.

Last update: 2024-12-23 11:28:16 UTC


README

Latest Stable Version License

Collection of additional asserts to be used with PHP Unit testing framework. Helpers are split into dedicated namespaces:

  • ExtraAsserts: various asserts to help testing your code,
  • Generator: various helper methods producing random values for your tests,

Installation

composer require --dev marcin-orlowski/phpunit-extra-asserts

Usage

As ExtraAsserts come as set of static methods so you just need to add related use to your test class and all the methods should be simply available via static reference ExtraAsserts::.... For example:

use \MarcinOrlowski\PhpunitExtraAsserts\ExtraAsserts;

class MyBaseTestClass extends ... {

    use \MarcinOrlowski\PhpunitExtraAsserts\ExtraAsserts;
    use \MarcinOrlowski\PhpunitExtraAsserts\Type;

    [...]

    public function testSomething(): void
    {
        [...]

        ExtraAsserts::assertIsType($val, [Type::STRING, Type::BOOL]);
        ExtraAsserts::assertRFC3339($stamp);
    }
}

Available asserts

NOTE: Deprecated methods will be removed in v5.4.0

Helper methods

Generator methods

License

  • Written and copyrighted ©2014-2022 by Marcin Orlowski
  • Open-sourced software licensed under the MIT license