PHPackages                             marcin-orlowski/phpunit-extra-asserts - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. marcin-orlowski/phpunit-extra-asserts

ActiveLibrary[Testing &amp; Quality](/categories/testing)

marcin-orlowski/phpunit-extra-asserts
=====================================

Extra asserts and helpers to make your unit testing easier.

5.3.0(2y ago)217.8k↑101%4MITPHPPHP ^8.0CI failing

Since Nov 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/MarcinOrlowski/phpunit-extra-asserts)[ Packagist](https://packagist.org/packages/marcin-orlowski/phpunit-extra-asserts)[ Docs](https://github.com/MarcinOrlowski/phpunit-extra-asserts)[ RSS](/packages/marcin-orlowski-phpunit-extra-asserts/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (4)Versions (23)Used By (4)

PhpUnit Extras Asserts
======================

[](#phpunit-extras-asserts)

[![Latest Stable Version](https://camo.githubusercontent.com/91cb03ba925d8dd742ac2dcb1017972c6942bc43a5a629cabc8682cae989e364/68747470733a2f2f706f7365722e707567782e6f72672f6d617263696e2d6f726c6f77736b692f706870756e69742d65787472612d617373657274732f762f737461626c65)](https://packagist.org/packages/marcin-orlowski/phpunit-extra-asserts)[![License](https://camo.githubusercontent.com/6ca86016ba77b979a6b1777210e518cefabf0c7730a262d9a520e6c343905952/68747470733a2f2f706f7365722e707567782e6f72672f6d617263696e2d6f726c6f77736b692f706870756e69742d65787472612d617373657274732f6c6963656e7365)](https://packagist.org/packages/marcin-orlowski/phpunit-extra-asserts)

Collection of additional asserts to be used with [PHP Unit](https://phpunit.de) 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
------------

[](#installation)

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

Usage
-----

[](#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
-----------------

[](#available-asserts)

AssertDescriptionAddedassertArrayElement(string $key, array $array, string $expected\_value)Asserts given array has specified key and it's value is according to expectations.v1.0.0assertArrayEquals(array $array\_a, array $array\_b)Asserts two arrays are equivalent.v1.0.0assertArrayHasKeys(array $required\_keys, array $array)Asserts array has ALL the required keys.v1.0.0assertArraysHaveDifferences(int $diff\_count, array $array\_a, array $array\_b)Asserts two arrays differ by exactly given number of elements (default is 0).v1.0.0assertRFC3339(string $stamp)Asserts provided string is valid RFC3339 timestamp string.v1.0.0assertRFC3339OrNull(string $stamp)Asserts $stamp string is valid RFC3339 timestamp string or @null.v1.0.0massAssertEquals(array $array\_a, array $array\_b, array $ignored\_keys)Assert if keys from response have the same values as in original array. Keys listed in $skip\_keys are ignored.v1.0.0assertIsObjectOrExistingClass(string OR object $cls\_or\_obj, ?string $var\_nam = null)Asserts given $value (which the value of variable named $var\_name) is an object or name name of existing class.v3.0.0\[DEPRECATED\] assertIsArray(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an array.v3.0.0\[DEPRECATED\] assertIsBool(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is a boolean.v3.0.0\[DEPRECATED\] assertIsFloat(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an float.v3.0.0\[DEPRECATED\] assertIsInteger(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an integer.v3.0.0\[DEPRECATED\] assertIsInteger(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an integer.v3.0.0\[DEPRECATED\] assertIsObject(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an object (of any class).v3.0.0\[DEPRECATED\] assertIsString(mixed $value, ?string $var\_name = null)Asserts given $value (which the value of variable named $var\_name) is an string.v3.0.0**NOTE:** Deprecated methods will be removed in v5.4.0

Helper methods
--------------

[](#helper-methods)

MethodDescriptionprintArray(array $array, int $indent)Prints content of given array in compacted form.Generator methods
-----------------

[](#generator-methods)

MethodDescriptiongetRandomString(?string $prefix = null, int $length = 24, string $separator = '\_')Returns string of total length equal to specified limit (incl. optional prefix or separator strings)getRandomStringOrNull(?string $prefix = null, int $length = 24, string $separator = '\_', float $trueValueProbability = 0.5)Returns either random `string` or `NULL`. Probability (float value in range 0-1) specifies the chance of drawing the `string` value. The higher the value of this argument, the higher the chance for `string` being returned.getRandomFloat(float $min, float $max, int $fractionalDigits = 0)Draws random `float` from given range. If given `max` is lower than `min`, these two will be swapped. If number of fractional digits is non-zero, value will be rounded to given number of fractional digits. Value `0` means not rounding.getRandomInt(int $min = 0, int $max = 100)Draws random `int` from given range. If given `max` is lower than `min`, these two will be swapped.getRandomBool(float $trueValueProbability = 0.5)Draws random `boolean` value. Float value (in 0-1 range) defining the chances of drawing the value of `TRUE`. The higher the of this argument, the higher the chances to draw `TRUE`.getRandomLatitude(float $min, float $max, int $round=0)Draws random latitude from given range (default is max allowed range). If given `max` is lower than `min`, these two will be swapped.getRandomLongitude(float $min, float $max, int $round=0)Draws random longitude from given range (default is max allowed range). If given `max` is lower than `min`, these two will be swapped.---

License
-------

[](#license)

- Written and copyrighted ©2014-2022 by Marcin Orlowski
- Open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~85 days

Recently: every ~133 days

Total

20

Last Release

802d ago

Major Versions

1.3.1 → 2.0.02022-01-16

2.0.0 → 3.0.02022-09-11

3.4.0 → 4.0.02022-11-04

4.0.0 → 5.0.02022-11-18

PHP version history (4 changes)1.0.1PHP &gt;=7.2.0

3.0.0PHP ^7.4||^8.0||^8.1

4.0.0PHP ^8.0||^8.1

5.3.0PHP ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8041294?v=4)[Marcin Orlowski](/maintainers/MarcinOrlowski)[@MarcinOrlowski](https://github.com/MarcinOrlowski)

---

Top Contributors

[![MarcinOrlowski](https://avatars.githubusercontent.com/u/8041294?v=4)](https://github.com/MarcinOrlowski "MarcinOrlowski (146 commits)")

---

Tags

phpunithelperassertstestsunittestsphp8

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/marcin-orlowski-phpunit-extra-asserts/health.svg)

```
[![Health](https://phpackages.com/badges/marcin-orlowski-phpunit-extra-asserts/health.svg)](https://phpackages.com/packages/marcin-orlowski-phpunit-extra-asserts)
```

###  Alternatives

[whatthejeff/nyancat-phpunit-resultprinter

Nyan Cat result printer for PHPUnit

282697.4k24](/packages/whatthejeff-nyancat-phpunit-resultprinter)[aik099/phpunit-mink

Library for using Mink in PHPUnit tests. Supports session sharing between tests in a test case.

72137.8k1](/packages/aik099-phpunit-mink)[phpunit/phpunit-dom-assertions

DOM assertions for PHPUnit

29374.8k13](/packages/phpunit-phpunit-dom-assertions)[janmarek/mockista

Mockista is library for mocking, which I've written, because I find mocking in PHPUnit awful.

29222.1k28](/packages/janmarek-mockista)[hot/phpunit-runner

The lib allows to watch phpunit tests

2967.3k4](/packages/hot-phpunit-runner)[code-distortion/adapt

A Laravel package that builds databases for your tests, improving their speed.

2838.1k](/packages/code-distortion-adapt)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
