PHPackages                             xp-forge/assert - 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. xp-forge/assert

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

xp-forge/assert
===============

Assertions for the XP Framework

v4.1.2(4y ago)0543BSD-3-ClausePHPPHP &gt;=7.0.0

Since Jan 10Pushed 4y ago2 watchersCompare

[ Source](https://github.com/xp-forge/assert)[ Packagist](https://packagist.org/packages/xp-forge/assert)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-forge-assert/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (10)Dependencies (2)Versions (18)Used By (0)

Assertions
==========

[](#assertions)

[![Build status on GitHub](https://github.com/xp-forge/assert/workflows/Tests/badge.svg)](https://github.com/xp-forge/assert/actions)[![XP Framework Mdodule](https://raw.githubusercontent.com/xp-framework/web/master/static/xp-framework-badge.png)](https://github.com/xp-framework/core)[![BSD Licence](https://raw.githubusercontent.com/xp-framework/web/master/static/licence-bsd.png)](https://github.com/xp-framework/core/blob/master/LICENCE.md)[![Requires PHP 7.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-7_0plus.svg)](http://php.net/)[![Supports PHP 8.0+](https://raw.githubusercontent.com/xp-framework/web/master/static/php-8_0plus.svg)](http://php.net/)[![Latest Stable Version](https://camo.githubusercontent.com/693901f11dd2ab51928bfd523146cf69d58542ddd0c997637df04e99b5ab5682/68747470733a2f2f706f7365722e707567782e6f72672f78702d666f7267652f6173736572742f76657273696f6e2e706e67)](https://packagist.org/packages/xp-forge/assert)

Flexible assertions on top of the XP Framework's unittest package.

Example
-------

[](#example)

```
use unittest\assert\{Assert, All};

class ExampleTest {

  #[@test]
  public function succeeds() {
    Assert::that(['The Dude'])->hasSize(1)->contains('The Dude');
  }

  #[@test]
  public function fails() {
    All::of(function() {
      Assert::that('localhost')->startsWith('www');
      Assert::that('example.com')->endsWith('.org');
    });
  }
}
```

Running this test will yield one succeeded and one failed test. The difference to regular unittest messages is the more readable format.

On top of that, this library's assertions are also more flexible: As seen in the above case, we wrapped the chain in an `All::of()` call which will yield *all* failed assertions, not just the first one.

```
$ xp test ExampleTest.class.php
[.F]

F unittest.TestAssertionFailed(test= ExampleTest::fails, time= 0.002 seconds) {
  unittest.AssertionFailedError{ The following 2 assertions have failures:
    1: unittest.AssertionFailedError{ Failed to verify that "localhost" starts with "www" }
    2: unittest.AssertionFailedError{ Failed to verify that "example.com" ends with ".org" }
   }
    at unittest.assert.All::of() [line 17 of ExampleTest.class.php]
    at ExampleTest::fails() [line 0 of StackTraceElement.class.php]
    at ReflectionMethod::invokeArgs() [line 90 of Method.class.php]
    at lang.reflect.Method::invoke() [line 334 of TestSuite.class.php]
    at unittest.TestSuite::runInternal() [line 565 of TestSuite.class.php]
    at unittest.TestSuite::run() [line 369 of Runner.class.php]
    at xp.unittest.Runner::run() [line 380 of Runner.class.php]
    at xp.unittest.Runner::main() [line 281 of class-main.php]

 }

✗: 2/2 run (0 skipped), 1 succeeded, 1 failed
Memory used: 1610.91 kB (1710.45 kB peak)
Time taken: 0.005 seconds
```

Assertions
----------

[](#assertions-1)

Generic assertions:

- `is(unittest.assert.Condition $condition)` - Asserts a given condition matches
- `isNot(unittest.assert.Condition $condition)` - Asserts a given condition does not match
- `isEqualTo(var $compare)` - Asserts the value is equal to a given comparison
- `isNotEqualTo(var $compare)` - Asserts the value is not equal to a given comparison
- `isNull()` - Asserts the value is null
- `isTrue()` - Asserts the value is true
- `isFalse()` - Asserts the value is false
- `isIn(var $enumerable)` - Asserts the value is in a given enumerable
- `isNotIn(var $enumerable)` - Asserts the value is not in a given enumerable
- `isInstanceOf(string|lang.Type $type)` - Asserts the value is of a given type

With special meanings dependant on type:

- `isEmpty()` - Asserts a string, array or map is empty
- `hasSize(int $size)` - Asserts a string length, array or map size
- `startsWith(var $element)` - Asserts a string or array contains the given element at its start
- `endsWith(var $element)` - Asserts a string or array contains the given element at its end
- `contains(var $element)` - Asserts a string, array or map contains a given element
- `doesNotContain(var $element)` - Asserts a string, array or map does not contain a given element

For numbers:

- `isGreaterThan(int|double $comparison)` - Asserts *value &gt; comparison*
- `isLessThan(int|double $comparison)` - Asserts *value &lt; comparison*
- `isBetween(int|double $start, int|double $end)` - Asserts *value &gt;= start &amp;&amp; value &lt;= end*
- `isCloseTo(int|double $comparison, int|double $tolerance)` - Asserts value is close (defined per tolerance)

Transformations
---------------

[](#transformations)

Values can be transformed prior to invoking assertions on them.

Extraction works directly on instances (using properties and `get`-prefixed as well as plain getters):

```
$tim= new Person(6100, 'Tim Tailor');
Assert::that($tim)->extracting('name')->isEqualTo('Tim Tailor');
```

You can also pass a closure to control more precisely what's extracted:

```
$tim= new Person(6100, 'Tim Tailor');
Assert::that($tim)->extracting(function($p) { return $p->name(); })->isEqualTo('Tim Tailor');
```

For maps, extraction accesses the elements by their string keys:

```
$person= ['id' => 6100, 'name' => 'Test', 'age' => 42];
Assert::that($person)->extracting('age')->isEqualTo(42);
```

Passing an array to `extracting()` will extract multiple elements and return them in an array in the order they're passed:

```
$person= ['id' => 6100, 'name' => 'Test', 'age' => 42];
Assert::that($person)->extracting(['name', 'age'])->isEqualTo(['Test', 42]);
```

Passing maps to `extracting()` will extract multiple elements and return them in a map.

```
$person= ['id' => 6100, 'name' => 'Test', 'age' => 42];
Assert::that($person)->extracting(['identifier' => 'id'])->isEqualTo(['identifier' => 6100]);
```

For arrays, the `extracting()` method applies the extraction on every element:

```
$people= [new Person(1, 'Queen'), new Person(2, 'King')];
Assert::that($people)->extracting('name')->isEqualTo(['Queen', 'King']);
```

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity67

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 ~173 days

Total

16

Last Release

1588d ago

Major Versions

v0.8.0 → v1.0.02015-12-14

v1.0.0 → v2.0.02016-02-21

v2.1.0 → v3.0.02017-06-04

v3.0.3 → v4.0.02020-04-10

PHP version history (3 changes)v0.6.0PHP &gt;=5.4.0

v3.0.0PHP &gt;=5.6.0

v4.0.0PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/07d18d882c8b4aaf3466432f64018214f2771eda333202175431ee7233795376?d=identicon)[thekid](/maintainers/thekid)

---

Top Contributors

[![thekid](https://avatars.githubusercontent.com/u/696742?v=4)](https://github.com/thekid "thekid (125 commits)")

---

Tags

assertionsphpunittestxp-frameworkmodulexp

### Embed Badge

![Health badge](/badges/xp-forge-assert/health.svg)

```
[![Health](https://phpackages.com/badges/xp-forge-assert/health.svg)](https://phpackages.com/packages/xp-forge-assert)
```

###  Alternatives

[xp-framework/compiler

XP Compiler

1926.8k10](/packages/xp-framework-compiler)

PHPackages © 2026

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