PHPackages                             khalyomede/matcha - 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. khalyomede/matcha

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

khalyomede/matcha
=================

Unit test library that taste good.

v0.13.2(7y ago)2302MITPHPPHP &gt;=7.2.0

Since Jun 17Pushed 7y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (26)Used By (2)

Matcha
======

[](#matcha)

Unit test library that taste good.

[![PHP from Packagist](https://camo.githubusercontent.com/f72f9673f1ea78e6829f5367ff89486d6e3e02dc2ad3998825421342a6ec9c72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f6d61746368612e737667)](https://camo.githubusercontent.com/f72f9673f1ea78e6829f5367ff89486d6e3e02dc2ad3998825421342a6ec9c72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6b68616c796f6d6564652f6d61746368612e737667)[![Packagist](https://camo.githubusercontent.com/cd0ab36e9a00af10d0eda8c8249e137466b0ae5d9a63d811723c5cf30f24f976/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f6d61746368612e737667)](https://camo.githubusercontent.com/cd0ab36e9a00af10d0eda8c8249e137466b0ae5d9a63d811723c5cf30f24f976/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b68616c796f6d6564652f6d61746368612e737667)[![Codeship](https://camo.githubusercontent.com/7b21e4474c7d9165df7e0e53139d8430d6f2166f49280b4ce0cd4b4c137b91f0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f64633961646565302d396234652d303133362d636337382d3361366466393663363032302e737667)](https://camo.githubusercontent.com/7b21e4474c7d9165df7e0e53139d8430d6f2166f49280b4ce0cd4b4c137b91f0/68747470733a2f2f696d672e736869656c64732e696f2f636f6465736869702f64633961646565302d396234652d303133362d636337382d3361366466393663363032302e737667)[![Packagist](https://camo.githubusercontent.com/ccf802ce1dc33366192c62563af4cfcb316de80e6eeb4b0705ba35c28d81ba83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f6d61746368612e737667)](https://camo.githubusercontent.com/ccf802ce1dc33366192c62563af4cfcb316de80e6eeb4b0705ba35c28d81ba83/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6b68616c796f6d6564652f6d61746368612e737667)

 [![Matcha logo](https://user-images.githubusercontent.com/15908747/41511668-c68e330e-727b-11e8-89b6-c18d2d07af18.png)](https://user-images.githubusercontent.com/15908747/41511668-c68e330e-727b-11e8-89b6-c18d2d07af18.png)

[![Gif of an example of usage](https://camo.githubusercontent.com/a52df9e3a2a7b1327ecbebfdb4dcdb3dfdbf07c02d9cddb53e7ec4605d27ff40/68747470733a2f2f696d6167652e6962622e636f2f654b50706a552f6c616e64696e672d706167652d6d61746368612d762d302d31332d312e676966)](https://camo.githubusercontent.com/a52df9e3a2a7b1327ecbebfdb4dcdb3dfdbf07c02d9cddb53e7ec4605d27ff40/68747470733a2f2f696d6167652e6962622e636f2f654b50706a552f6c616e64696e672d706167652d6d61746368612d762d302d31332d312e676966)

Summary
-------

[](#summary)

- [Installation](#installation)
- [Examples](#examples)
- [Full example](#full-example)
- [API](#api)
- [Credits](#credits)

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

[](#installation)

In your project root folder:

```
composer require --dev khalyomede/matcha:0.*
```

Examples
--------

[](#examples)

- [Example 1: testing if a code returns a string](#example-1-testing-if-a-code-returns-a-string)
- [Example 2: testing if a value is true](#example-2-testing-if-a-code-returns-true)
- [Example 3: testing if a code returns null](#example-3-testing-if-a-code-returns-null)
- [Example 4: testing the negativity of an expression](#example-4-testing-the-negativity-of-an-expression)
- [Example 5: testing if a message has been displayed](#example-5-testing-if-a-message-has-been-displayed)
- [Example 6: testing if a variable returns the desired type](#example-6-testing-if-a-variable-returns-the-desired-type)
- [Example 7: testing against a string format](#example-7-testing-against-a-string-format)
- [Example 8: testing if a database is reachable](#example-8-testing-if-a-database-is-reachable)
- [Example 9: make the console report detailed](#example-9-make-the-console-report-detailed)
- [Example 10: using matcha console command on a single file](#example-10-using-matcha-console-command-on-a-single-file)
- [Example 11: using matcha console command on a folder](#example-11-using-matcha-console-command-on-a-folder)

### Example 1: testing if a code returns a string

[](#example-1-testing-if-a-code-returns-a-string)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('trim', function() {
  it('should return the same string if the string has no spaces around', function() {
    expect( trim('hello world') )->toBe()->equalTo('hello world');
  });
});

return run();
```

### Example 2: testing if a value is true

[](#example-2-testing-if-a-value-is-true)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('empty', function() {
  it('should return true if the string has no characters', function() {
    expect( empty('') )->toBe()->true();
  });
});

return run();
```

### Example 3: testing if a code returns false

[](#example-3-testing-if-a-code-returns-false)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('isset', function() {
  it('should return false if the variable does not exists', function() {
    expect( isset($GLOBALS['php6']) )->toBe()->false();
  });
});

return run();
```

### Example 4: testing the negativity of an expression

[](#example-4-testing-the-negativity-of-an-expression)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('array-sum', function() {
  it('should not return null', function() {
    expect( array_sum([1, 2, 3]) )->not()->toBe()->null();
  });
});

return run();
```

### Example 5: testing if a message has been displayed

[](#example-5-testing-if-a-message-has-been-displayed)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('echo', function() {
  it('it should display the correct message', function() {
    expect(function() {
      echo 'hello world';
    })->toDisplay('hello world');
  });
});

return run();
```

### Example 6: testing if a variable returns the desired type

[](#example-6-testing-if-a-variable-returns-the-desired-type)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('empty', function() {
  it('it should return true if an array is empty', function() {
    expect( empty([]) )->toBe()->aBoolean();
  });
});

return run();
```

### Example 7: testing against a string format

[](#example-7-testing-against-a-string-format)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('json', function() {
  it('should be a valid json string', function() {
    expect('{"hello": "world"}')->toBe()->aString()->inJsonFormat();
  });
});

return run();
```

### Example 8: testing if a database is reachable

[](#example-8-testing-if-a-database-is-reachable)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('database connectivity', function() {
  it('should be reachable', function() {
    expect([
      'driver' => 'mysql',
      'host' => 'ensembldb.ensembl.org',
      'user' => 'anonymous'
    ])->toBe()->aDatabase()->thatIsAccessible();
  });
});

return run();
```

### Example 9: make the console report detailed

[](#example-9-make-the-console-report-detailed)

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;
use Khalyomede\ReportLevel;

describe('array', function() {
  it('should merge two arrays', function() {
    expect( array_merge([1, 2, 3], [4, 5, 6]) )->toBe()->equalTo([1, 2, 3, 4, 5, 6]);
  });

  it('should diff two array', function() {
    expect( array_count_values([1, 1, 3]) )->toBe()->equalTo([1 => 2, 3 => 1]);
  });

  it('should shuffle an array', function() {
    $array = [1, 2];

    expect( shuffle($array) )->toBe()->anArray();
  });
});

report('detailed');
// or
report(ReportLevel::DETAILED);

return run();
```

### Example 10: using matcha console command on a single file

[](#example-10-using-matcha-console-command-on-a-single-file)

```
use function Khalyomede\Style\expect;

describe('abs', function() {
  it('it should give the absolute value for a positive value', function() {
    expect(abs(-10 + 2))->toBe()->equalTo(8);
  });

  it('should give the absolute value for a positive value', function() {
    expect(abs(10 + 2))->toBe()->equalTo(12);
  });
});
```

```
$ bin/matcha example/tests/example-10.php

  2018-10-13 18:55:11.628200  ⓘ  Running tests for "abs"
  2018-10-13 18:55:11.630700  ⚐  2 tests completed, 0 tests failed
  2018-10-13 18:55:11.630800  ⚐  tests ran in 0.0015 sec. (+0.0018 sec.)
  2 / 2 ▓▓ 100 %
```

### Example 11: using matcha console command on a folder

[](#example-11-using-matcha-console-command-on-a-folder)

*Check /example/tests, all the files that ends with `.php`. You are not constraint by the extension `.test.php`, you can ommit it.*

```
$ bin/matcha example/tests/

  2018-10-13 18:58:05.348300  ⓘ  Running tests for "abs"
  2018-10-13 18:58:05.351300  ⓘ  Running tests for "array_sum"
  2018-10-13 18:58:05.351400  ⓘ  Running tests for "count"
  2018-10-13 18:58:05.351500  ⚐  8 tests completed, 0 tests failed
  2018-10-13 18:58:05.351500  ⚐  tests ran in 0.0019 sec. (+0.0022 sec.)
  8 / 8 ▓▓▓▓▓▓▓▓ 100 %
```

Full example
------------

[](#full-example)

This example is intended to show you how can all of these function can be mixed together.

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('trim', function() {
  it('should return a string when triming a string', function() {
    expect(trim('hello world'))->toBe()->aString();
  });

  it('should return a string even if triming null', function() {
    expect(trim(null))->toBe()->aString();
  });

  it('should return the same string when triming a string without spaces around', function() {
    expect(trim('hello world'))->toBe()->equalTo('hello world');
  });

  it('should return the string without spaces around if triming a string with spaces around', function() {
    expect(trim(' hello world '))->toBe()->equalTo('hello world');
  });
});

describe('empty', function() {
  it('should return true if checking null', function() {
    expect(empty(null))->toBe()->strictly()->true();
  });

  it('should return true if checking false', function() {
    expect(empty(false))->toBe()->true();
  });

  it('should return true if checking an empty array', function() {
    expect(empty([]))->toBe()->true();
  });
});

describe('isset', function() {
  it('should return false if a variable is not set', function() {
    expect(isset($php6))->toBe()->false();
  });

  it('should return true if an array is set', function() {
    expect(isset($_GET))->toBe()->true();
  });
});

return run();
```

API
---

[](#api)

- [describe](#describe)
- [expect](#expect)
    - [not](#not)
    - [strictly](#strictly)
    - [toBe](#tobe)
        - [aBoolean](#aBoolean)
        - [aDatabase](#aDatabase)
            - [thatIsAccessible](#thatIsAccessible)
        - [aDouble](#aDouble)
        - [aFile](#aFile)
        - [aFloat](#aFloat)
        - [aFunction](#aFunction)
        - [anArray](#anArray)
        - [anObject](#anObject)
        - [anInstanceOf](#anInstanceOf)
        - [anInteger](#anInteger)
        - [aResource](#aResource)
        - [aString](#aString)
            - [inJsonFormat](#inJsonFormat)
        - [equalTo](#equalto)
            - [false](#false)
            - [null](#null)
            - [true](#true)
    - [toDisplay](#toDisplay)
    - [toThrow](#toThrow)
        - [theException](#theException)
        - [theMessage](#theMessage)
- [it](#it)
- [report](#report)
- [run](#run)

### expect

[](#expect)

Returns a new Expect instance.

```
function expect($mixed): Expect
```

```
require(__DIR__  '/../vendor/autoload.php');

use function Khalyomede\Expect;

expect( empty('hello world') );
```

```
require(__DIR__  '/../vendor/autoload.php');

use function Khalyomede\Expect;

expect(function() {
  throw new Exception('exception manually thrown');
});
```

### not

[](#not)

Asserts that we expect the inverse of the test.

```
public function not(): Expect
```

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('empty', function() {
  it('should not return true if the string is not empty', function() {
    expect( empty('hello world') )->not()->toBe()->true();
  });
});

return run();
```

### strictly

[](#strictly)

Asserts that we expect the test to be also type-tested (this will prevent from PHP to perform implicit cast when running the test).

```
public function strictly(): Expect
```

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('int cast', function() {
  it('should return the integer equivalent of the string representation of a number', function() {
    expect((int) '1')->toBe()->strictly()->equalTo(1);
  });
});

return run();
```

### toBe

[](#tobe)

Asserts that we are testing an equality.

```
public function toBe(): Expect
```

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('trim', function() {
  it('should return the same string if it has no spaces around', function() {
    expect( trim('hello world') )->toBe()->equalTo('hello world');
  });
});

return run();
```

### equalTo

[](#equalto)

Asserts that we are testing an equality against a particular value.

```
public function equalTo($mixed): Expect
```

```
require(__DIR__ . '/../vendor/autoload.php');

use function Khalyomede\Style\expect;

describe('implicit cast', function() {
  it('should implicitly cast the string representation of a number', function() {
    expect('1')->toBe()->equalTo(1)
  });
});

return run();
```

### Report

[](#report)

Update the level of report in console.

```
function report(string $level): void
```

Available reports levels are `detailed`, `normal` (by default) and `reduced`.

Reports levels can be used through `Khalyomede\ReportLevel` class:

```
use Khalyomede\ReportLevel;

ReportLevel::DETAILED;
ReportLevel::NORMAL;
ReportLevel::REDUCED;
```

Credits
-------

[](#credits)

- Logo by [Made](https://thenounproject.com/made.somewhere/) from [Noun project](https://thenounproject.com/) (modified version of logo is currenctly used, check out the [original version](https://thenounproject.com/term/green-tea/952777/))

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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

Total

25

Last Release

2754d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15908747?v=4)[Anwar](/maintainers/khalyomede)[@khalyomede](https://github.com/khalyomede)

---

Tags

libraryphptestingunit-testtestingunittesttool

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/khalyomede-matcha/health.svg)

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

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.5k](/packages/mockery-mockery)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

56426.3M455](/packages/dg-bypass-finals)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33412.5M345](/packages/brain-monkey)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[funkatron/funit

The testing microframework for PHP 5.3+, partially inspired by QUnit.

841.9k14](/packages/funkatron-funit)[sofa/eloquent-testsuite

Helpers for fast and reliable UNIT tests for your Eloquent Models with PHPUnit

10104.7k](/packages/sofa-eloquent-testsuite)

PHPackages © 2026

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