PHPackages                             toast/unit - 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. toast/unit

ActiveLibrary

toast/unit
==========

Super-simple unit testing for PHP7

2.2.2(1y ago)095914MITPHPPHP &gt;=8.1

Since Apr 30Pushed 1y ago2 watchersCompare

[ Source](https://github.com/toast-php/unit)[ Packagist](https://packagist.org/packages/toast/unit)[ RSS](/packages/toast-unit/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (34)Used By (14)

Toast\\Unit
===========

[](#toastunit)

Toast is a super-simple testing framework for PHP, inspired by Javascript testing frameworks like Karma, Jasmine etc.

Toast was born out of frustration with existing testing frameworks which (in our view) are needlessly bulky, complex and difficult to setup. Some are also excruciatingly slow (looking at you, PHPUnit).

Features
--------

[](#features)

- *Very* fast
- Assertions using native PHP `assert`
- Feature descriptions using DocComments
- Grouping of related tests

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

[](#installation)

```
$ composer require --dev toast/unit
```

Create a `Toast.json` config file in the root of your project. It should contain at least a `"tests"` key pointing to the directory where you've placed your tests. Tests may be placed in (sub)directories; Toast will recurse.

Optionally the config can also contain a `"bootstrap"` key with an array of files to include prior to running. These can contain your project's setup (e.g. dependency injection logic).

Turn on assertions and configure them to throw `AssertionError` on failure. See [this section in the manual](http://php.net/manual/en/function.assert.php); both values should be set to `1`.

Configuration
-------------

[](#configuration)

Place a configuration file in de root of your project (or optionally specify it as a parameter when running Toast). The file supports all formats [Kingconf](https://github.com/monomelodies/kingconf) supports; we'll use JSON here.

An example config file:

```
{
    "tests": "path/to/my/tests"
}
```

Yep, that's it :)

Usage
-----

[](#usage)

```
$ vendor/bin/toast
```

That's it :) You may optionally speficy a `--filter=` parameter containing a regular expression. In that case only tests with matching file names will be run. Filters are case-insensitive and `"@"` is used as a delimiter.

Other optional flags are:

- `-v` for verbose mode
- `-o` for output mode (see below)

Writing tests
-------------

[](#writing-tests)

This couldn't be simpler! Each test(group) is a *callable*. Toast assumes any callable returning a `Generator` is a group; other callables are the actual tests. For example:

```
