PHPackages                             williams/testtube - 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. williams/testtube

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

williams/testtube
=================

TestTube: A lightweight and extensible unit testing framework for PHP.

v0.1.0(1y ago)06MITPHP

Since Oct 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bwilliams-uk/TestTube)[ Packagist](https://packagist.org/packages/williams/testtube)[ RSS](/packages/williams-testtube/feed)WikiDiscussions master Synced 1mo ago

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

TestTube: Unit Testing Framework
================================

[](#testtube-unit-testing-framework)

TestTube is a lightweight and extensible unit testing framework for PHP. Originally built to support the [Xpression](http://github.com/bwilliams-uk/xpression) library, its design prioritizes flexibility, making it suitable for small to medium-sized projects.

Requirements
------------

[](#requirements)

- **Composer** must be installed.

Installation
------------

[](#installation)

1. Create a new TestTube project (you can replace 'example' with your desired directory name):

```
composer create-project williams/testtube example
```

2. Configure `composer.json` to autoload the PHP libraries you want to test:

```
"autoload": {
    "psr-4": {
        "Namespace\\Of\\Library\\" : "path/to/library/"
    }
}
```

3. Regenerate autoload files:

```
composer dump-autoload
```

Writing Your First Test
-----------------------

[](#writing-your-first-test)

Let’s create a simple test for a `Calculator` class.

1. Inside the `tests` directory, create a folder to group your test files (e.g., `demo`). Create a PHP file for your tests, such as `calculator.php`:

```
//tests/demo/calculator.php

return new class extends BaseTest{
};
```

2. Define a `boot` method to instantiate the object(s) required for your tests:

```
use Demo\Calculator;

return new class extends BaseTest{

    public function boot(){
        return new Calculator;
    }
};
```

If more than one object is required, return an array containing the objects:

```
return [ new Foo, new Bar ];
```

3. Create a test method. Each test method should take as parameters the objects returned by the `boot` method. By default, test method names must be camel-cased and start with 'test':

```
use Demo\Calculator;

return new class extends BaseTest{

    public function boot(){
        return new Calculator;
    }

    public function testAdd($calculator){

    }

};
```

4. Define the body of the test, using an appropriate `assert` method:

```
   public function testAdd($calculator){
       $output = $calculator->add(2,3);
       $this->assertEquals(5,$output);
   }
```

5. Run your tests from the project's root directory

```
php test
```

Example Output:

```
1 test file found.
1 test (1 assertion). 1 Passed, 0 Failed.

```

5. Modify the expected value to simulate a failed test:

```
$this->assertEquals(6, $result); // Intentionally wrong
```

Re-running the tests will produce:

```
1 test file found.
1 test (1 assertion). 0 Passed, 1 Failed.

The following assertions were unsuccessful:

[demo/calculator.php] Failed to assert 6 equals 5.

```

> Once a test file contains more than one test, the output will show both the filename and method name to help pinpoint failures.

Advanced Features
-----------------

[](#advanced-features)

### Assertions

[](#assertions)

TestTube includes several `assert` methods:

- `assertEquals($expected, $actual, $failureMessage = null)`
- `assertTrue($boolean, $failureMessage = null)`
- `assertFalse($boolean, $failureMessage = null)`

The `$failureMessage` parameter is optional, and a default message will be generated if omitted.

### Custom Test Method Names

[](#custom-test-method-names)

If you need non-standard test method names, you can declare them using the `$useMethods` property. You can also disable automatic detection of test methods starting with "test" by setting `$useTestMethods` to `false`:

```
return new class extends BaseTest {
    protected $useMethods = ['customTest'];
    protected $useTestMethods = false;

    public function customTest() {
        // This is a valid test method.
    }

    public function testExample() {
        // This method will not be treated as a test due to $useTestMethods being false.
    }
};
```

### Templates

[](#templates)

To follow the DRY (Don't Repeat Yourself) principle, TestTube allows you to extend from templates stored in the `templates` directory. For example, to share a `boot` method across multiple test files:

1. Create a reusable template:

```
// templates/CalculatorBaseTest.php

use Demo\Calculator;

class CalculatorBaseTest extends BaseTest{

    public function boot(){
        return new Calculator;
    }
}
```

2. In your test file, extend this template:

```
// tests/demo/calculator.php

return new class extends CalculatorBaseTest{

    public function testAdd($calculator){
        $output = $calculator->add(2,3);
        $this->assertEquals(5,$output);
    }
};
```

### The `setup` Method

[](#the-setup-method)

The `setup` method helps to maintain a separation of concerns between object creation and configuration. It allows for any further customisation of the objects returned by the `boot` method before each test. Like test methods, it must accept each object returned by `boot` as a parameter:

```
return new class extends CalculatorBaseTest {
    public function setup($calculator) {
        $calculator->useRadians();
        $calculator->roundDecimalPlaces(2);
    }
};
```

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance36

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

592d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c99edde3f9f8c1bf87a077618cd96dad78a63e69e579965ad9dd17b4e078264?d=identicon)[bwilliams-uk](/maintainers/bwilliams-uk)

---

Top Contributors

[![bwilliams-uk](https://avatars.githubusercontent.com/u/38534904?v=4)](https://github.com/bwilliams-uk "bwilliams-uk (1 commits)")

### Embed Badge

![Health badge](/badges/williams-testtube/health.svg)

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

###  Alternatives

[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[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)

PHPackages © 2026

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