PHPackages                             xp-framework/unittest - 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-framework/unittest

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

xp-framework/unittest
=====================

Unittests for the XP Framework

v11.4.1(2y ago)0301.4k↑72.7%20BSD-3-ClausePHPPHP &gt;=7.0.0

Since Aug 6Pushed 2y ago2 watchersCompare

[ Source](https://github.com/xp-framework/unittest)[ Packagist](https://packagist.org/packages/xp-framework/unittest)[ Docs](http://xp-framework.net/)[ RSS](/packages/xp-framework-unittest/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (52)Used By (20)

Unittests
=========

[](#unittests)

[![Build status on GitHub](https://github.com/xp-framework/compiler/workflows/Tests/badge.svg)](https://github.com/xp-framework/compiler/actions)[![XP Framework Module](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/12fd0fe340ceadb070f09ffd3e5bc3945bd3f2e11d6f3c7b634782bbbbfcf4a8/68747470733a2f2f706f7365722e707567782e6f72672f78702d6672616d65776f726b2f756e6974746573742f76657273696f6e2e706e67)](https://packagist.org/packages/xp-framework/unittest)

Unittests for the XP Framework

Writing a test
--------------

[](#writing-a-test)

Tests reside inside a class and are annotated with the `@test` attribute.

```
use unittest\{Assert, Test};

class CalculatorTest {

  #[Test]
  public function addition() {
    Assert::equals(2, 1 + 1);
  }
}
```

To run the test, use the `test` subcommand:

```
$ xp test CalculatorTest
[.]

♥: 1/1 run (0 skipped), 1 succeeded, 0 failed
Memory used: 1672.58 kB (1719.17 kB peak)
Time taken: 0.000 seconds
```

Assertion methods
-----------------

[](#assertion-methods)

The unittest package provides the following six assertion methods:

```
public abstract class unittest.Assert {
  public static void equals(var $expected, var $actual, string $error)
  public static void notEquals(var $expected, var $actual, string $error)
  public static void true(var $actual, string $error)
  public static void false(var $actual, string $error)
  public static void null(var $actual, string $error)
  public static void instance(string|lang.Type $type, var $actual, string $error)
  public static void throws(string|lang.Type $type, callable $block)
}
```

*If you need more than that, you can use [xp-forge/assert](https://github.com/xp-forge/assert) on top of this library.*

Setup and teardown
------------------

[](#setup-and-teardown)

In order to run a method before and after the tests are run, annotate methods with the `@before` and `@after` attributes:

```
use unittest\{Assert, Before, After, Test};

class CalculatorTest {
  private $fixture;

  #[Before]
  public function newFixture() {
    $this->fixture= new Calculator();
  }

  #[After]
  public function cleanUp() {
    unset($this->fixture);
  }

  #[Test]
  public function addition() {
    Assert::equals(2, $this->fixture->add(1, 1));
  }
}
```

*Note: All test methods are run with the same instance of CalculatorTest!*

Expected exceptions
-------------------

[](#expected-exceptions)

The *Expect* attribute is a shorthand for catching exceptions and verifying their type manually.

```
use lang\IllegalArgumentException;
use unittest\{Test, Expect};

class CalculatorTest {

  #[Test, Expect(IllegalArgumentException::class)]
  public function cannot_divide_by_zero() {
    (new Calculator())->divide(1, 0);
  }
}
```

Ignoring tests
--------------

[](#ignoring-tests)

The *Ignore* attribute can be used to ignore tests. This can be necessary as a temporary measure or when overriding a test base class and not wanting to run one of its methods.

```
use unittest\{Test, Ignore};

class EncodingTest {

  #[Test, Ignore('Does not work with all iconv implementations')]
  public function transliteration() {
    /* ... */
  }
}
```

Parameterization
----------------

[](#parameterization)

The *Values* attribute can be used to run a test with a variety of values which are passed as parameters.

```
use lang\IllegalArgumentException;
use unittest\{Test, Expect, Values};

class CalculatorTest {

  #[Test, Expect(IllegalArgumentException::class), Values([1, 0, -1])]
  public function cannot_divide_by_zero($dividend) {
    (new Calculator())->divide($dividend, 0);
  }
}
```

Actions
-------

[](#actions)

To execute code before and after tests, test actions can be used. The unittest library comes with the following built-in actions:

- `unittest.actions.ExtensionAvailable(string $extension)` - Verifies a given PHP extension is loaded.
- `unittest.actions.IsPlatform(string $platform)` - Verifies tests are running on a given platform via case-insensitive match on `PHP_OS`. Prefix with `!` to invert.
- `unittest.actions.RuntimeVersion(string $version)` - Verifies tests are running on a given PHP runtime. See [version\_compare](http://php.net/version_compare) for valid syntax.
- `unittest.actions.VerifyThat(function(): var|string $callable)` - Runs the given function, verifying it neither raises an exception nor return a false value.

```
use unittest\actions\{IsPlatform, VerifyThat};
use unittest\{Test, Action};

class FileSystemTest {

  #[Test, Action(eval: 'new IsPlatform("!WIN")')]
  public function not_run_on_windows() {
    // ...
  }

  #[Test, Action(eval: 'new VerifyThat(fn() => file_exists("/\$Recycle.Bin");')]
  public function run_when_recycle_bin_exists() {
    // ...
  }
}
```

Multiple actions can be run around a test by passing an array to the *@action* attribute.

Further reading
---------------

[](#further-reading)

- [XP RFC #0283: Unittest closure actions](https://github.com/xp-framework/rfc/issues/283)
- [XP RFC #0272: Unittest actions](https://github.com/xp-framework/rfc/issues/272)
- [XP RFC #0267: Unittest parameterization](https://github.com/xp-framework/rfc/issues/267)
- [XP RFC #0188: Test outcome](https://github.com/xp-framework/rfc/issues/188)
- [XP RFC #0187: @expect withMessage](https://github.com/xp-framework/rfc/issues/187)
- [XP RFC #0150: Before and after methods for test cases](https://github.com/xp-framework/rfc/issues/150)
- [XP RFC #0145: Make unittests strict](https://github.com/xp-framework/rfc/issues/145)
- [XP RFC #0059: Timeouts for unittests](https://github.com/xp-framework/rfc/issues/59)
- [XP RFC #0032: Add attributes for Unittest API](https://github.com/xp-framework/rfc/issues/32)
- [XP RFC #0020: Metadata for unittests](https://github.com/xp-framework/rfc/issues/20)

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity71

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

Recently: every ~223 days

Total

49

Last Release

912d ago

Major Versions

v6.10.1 → v7.0.02016-02-21

v7.2.0 → v8.0.02017-05-25

v8.0.0 → v9.0.02017-05-28

v9.7.1 → v10.0.02019-10-06

v10.1.1 → v11.0.02019-11-30

PHP version history (4 changes)v6.4.2PHP &gt;=5.4.0

v6.5.0PHP &gt;=5.5.0

v8.0.0PHP &gt;=5.6.0

v11.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 (359 commits)")

---

Tags

annotationsphptestcaseunittestxp-frameworkmodulexp

### Embed Badge

![Health badge](/badges/xp-framework-unittest/health.svg)

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

###  Alternatives

[docler-labs/codeception-slim-module

Codeception Module for Slim framework.

13178.0k1](/packages/docler-labs-codeception-slim-module)

PHPackages © 2026

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