PHPackages                             annexus/testsuite - 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. annexus/testsuite

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

annexus/testsuite
=================

Simple unit test and mocking framework

1.0.3(10y ago)028MITPHPPHP &gt;=5.4.0

Since Jul 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/annexus/testsuite)[ Packagist](https://packagist.org/packages/annexus/testsuite)[ RSS](/packages/annexus-testsuite/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (0)

TestSuite
=========

[](#testsuite)

Unit Test &amp; Mocking Framework for PHP.

Create mocks and stubs on the fly with the Mock Framework and Unit test your code with the Unit Test framework. This all comes in one pakcage, ready and easy to be used!

Quick guide
===========

[](#quick-guide)

A simple unit test and mocking framework.

Simply install the testsuite through composer:

```
/> composer require annexus/testsuite

```

Now create a folder in your project that will contain all your tests. In that folder create a simple test class (see description below for a simple example). Note, the filename MUST be the same as your class name. Example:

File: SomeTest.php You should then name your class like so: `class SomeTest { }`

Now you're ready to run your test. The command from console should look like this:

```
/> php [path to TestSuite.phar] [path to folder containing tests]

```

Or, if you want to load a bootstrap file like composers "autoload.php" or your custom file:

```
/> php --bootstrap [path to bootstrap file] [path to TestSuite.phar] [path to folder containing tests]

```

Example:

```
/> php /var/www/vendor/annexus/testsuite/TestSuite.phar /var/www/tests

```

Or with bootstrap file

```
/> php --bootstrap /var/www/vendor/autoload.php /var/www/vendor/annexus/testsuite/TestSuite.phar /var/www/tests

```

Creating a Unit Test
====================

[](#creating-a-unit-test)

A Unit Test class (or Test Case) can have any name and must always extend from **CFUnitTestCase** and therfor this class must be included. It is important that the class name of the Unit Test is the same as the file name.

A test method MUST have **Test\_** as prefix. All other methods will not be run by the Test Suite.

```
class ExampleTestCase extends CFUnitTestCase
{
    public function Test_A_simple_assertion()
    {
        $this->assert(5)->should()->be(5)->and()->beGreaterThan(2);
    }
}
```

Additionally a Test Case can also have one of the following methods:

```
public function setUp() - This is run before each test method is executed
public functin tearDown() - This is run at the end of each test method
public function setUpBeforeClass() - This is run before any test method is executed
public function tearDownAfterClass() - This is run after all test methods are executed
```

Fluent Assertions
=================

[](#fluent-assertions)

An assertion can be made in a fluent way. The following assertions are supported.

```
// Mixed assertion
$this->assert($string)->Should()->be('something');
$this->assert($array)->Should()->be($someOtherArray);
$this->assert($bool)->Should()->notBe(true);

// Type checking
$this->assert($string)->Should()->beAString();
$this->assert($object)->Should()->beAnObject();
$this->assert($array)->Should()->beAnArray();
$this->assert($int)->Should()->beAnInt();
$this->assert($float)->Should()->beAFloat();
$this->assert($bool)->Should()->beTrue();
$this->assert($bool)->Should()->beFalse();
$this->assert($mixed)->Should()->NotBeNull();
$this->assert($mixed)->Should()->beNull()
$this->assert($string)->Should()->beEmpty();
$this->assert($string)->Should()->NotBeEmpty();

// String specific assertions
$this->assert($string)->should()->haveLength(5);
$this->assert($string)->should()->beEquivalentTo($someString); // Case insensitive compare
$this->assert($string)->should()->startsWith($someString); // Case sensitive compare
$this->assert($string)->should()->startsWithEquivalent($someString); // Case insensitive compare
$this->assert($string)->should()->endWith($someString); // Case sensitive compare
$this->assert($string)->should()->endWithEquivalent($someString); // Case insensitive compare
$this->assert($string)->should()->contain($someText);
$this->assert($string)->should()->notContain($someText);
$this->assert($string)->should()->containEquivalentOf($someString); // Case insensitive compare (also on array values)
$this->assert($string)->should()->notContainEquivalentOf($someString); // Case insensitive compare (also on array values)

// Array specific assertions
$this->assert($array)->should()->contain($someOtherArray); // On intersect = success
$this->assert($array)->should()->notContain($someOtherArray); // When not intersects = success
$this->assert($array)->should()->notContainNull();

// Number assertions
$this->assert($int)->should()->beGreaterOrEqualTo($number);
$this->assert($int)->should()->beGreaterThan($number);
$this->assert($int)->should()->beLessOrEqualTo($number);
$this->assert($int)->should()->beLessThan($number);
$this->assert($int)->should()->bePositive();
$this->assert($int)->should()->beNegative();
$this->assert($int)->should()->beInRange($min, $max); //min=1, max=2 and given=2 will result in success

// Date assertions
$this->assert($datetime)->should()->beAfter($someDatetime);
$this->assert($datetime)->should()->beBefore($someDatetime);
$this->assert($datetime)->should()->beOnOrAfter($someDatetime);
$this->assert($datetime)->should()->beOnOrBefore($someDatetime);

// Throwable assertions
$this->assert()->should()->shouldThrow($func); Give the method that should be executed as an anonymous function to this method.
$this->assert()->should()->shouldThrow($func)->WithMessage('Exact exception message');
$this->assert()->should()->shouldThrow($func)->WithMessage('* psrtial message'); // The asterisk acts as a wild card. Can be used at the beginning, end or both sides of the string
$this->assert()->should()->shouldNotThrow($func);

// Extending assertions with "And()"
$this->assert($string)->should()->beAString()->and()->HaveLength(5);
```

Mocking
=======

[](#mocking)

When you want to mock an object then you must first include the class **CFMock/CFMock.php**. Now mocking will be a breeze.

You create a mocked version of an object like this:

```
$mock = new Mock::create( 'DummyClass' );
$mock->aCallTo('SomeMethod')->returns('some value');

// Or even namespaced classes can be loaded:
$mock = new Mock::create( '\Some\Namespace\DummyClass' );
```

Calls can then be made on the **$mock** object.

The mock framework also comes with a few assertions.

```
expectCallCount(2); // Expects that many calls to a certain method
expectMinimumCallCount(2); // Expects at least that many calls to a certain method
expectMaximumCallCount(2); // Expects a maximum of 2 calls to a method, less is fine as well
expectNever(); // A certain method should never be called
expectOnce(); // Only a single call is expected to be made to a certain method
```

A typical setup for a mock test could be this:

```
$mock = new Mock::create( 'DummyClass' );
$mock->aCallTo('SomeMethod')->returns('some value')->expectOnce();

$mock->someMethod('message'); // Will return the string: 'some value'
```

This is obviously not a real world example, but it should illustrate the idea.

Run Unit Tests
==============

[](#run-unit-tests)

WebRunner
---------

[](#webrunner)

When you have created your unit tests then these can easily be run from the browser. Simply browse to **"vendor/testsuite/annexus/Unit/Runners/WebWebRunner.php"**

In there you can simply hit the "Run Tests" button or select the tests you want to run.

Command line
------------

[](#command-line)

You can also run tests through command line:

There are two ways to run tests:

1. TestSuite.phar "Path/to/testFolder/"
2. TestSuite.phar --bootstrap "location/to/your/bootstrap/file.php" "Path/to/testFolder/"

Notice that "--bootstrap" **MUST** come as the first argument. That command could be useful for example to load the "autoload.php" file that comes with composer. So you have access to all your classes in your Unit Tests.

Screenshot
==========

[](#screenshot)

[![Example test with selected tests](https://camo.githubusercontent.com/be327d59b20c183af638bdf6b60a0271aa3fd3af7c68e4db282d0a66531d07a4/687474703a2f2f692e696d6775722e636f6d2f356c43386f32662e706e67)](https://camo.githubusercontent.com/be327d59b20c183af638bdf6b60a0271aa3fd3af7c68e4db282d0a66531d07a4/687474703a2f2f692e696d6775722e636f6d2f356c43386f32662e706e67)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

3961d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/29aaa3d81fa3965ee43634cf03baecc70d5da90e9633d5479e845af64ea5bc9b?d=identicon)[annexus](/maintainers/annexus)

### Embed Badge

![Health badge](/badges/annexus-testsuite/health.svg)

```
[![Health](https://phpackages.com/badges/annexus-testsuite/health.svg)](https://phpackages.com/packages/annexus-testsuite)
```

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[beberlei/assert

Thin assertion library for input validation in business models.

2.4k96.9M570](/packages/beberlei-assert)[mikey179/vfsstream

Virtual file system to mock the real file system in unit tests.

1.4k108.0M2.7k](/packages/mikey179-vfsstream)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[phpspec/phpspec

Specification-oriented BDD framework for PHP 7.1+

1.9k36.7M3.1k](/packages/phpspec-phpspec)

PHPackages © 2026

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