PHPackages                             memran/php-testify - 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. memran/php-testify

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

memran/php-testify
==================

Expressive PHP testing on top of PHPUnit with expect() assertions, describe()/it() specs, and watch mode.

v1.1.0(1mo ago)0231MITPHPPHP ^8.2

Since Oct 25Pushed 6mo agoCompare

[ Source](https://github.com/memran/php-testify)[ Packagist](https://packagist.org/packages/memran/php-testify)[ RSS](/packages/memran-php-testify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (1)

🧪 PHP-Testify
=============

[](#-php-testify)

A modern, expressive testing library for PHP with a fluent and intuitive API, built on top of PHPUnit.

📦 Stats &amp; Status
--------------------

[](#-stats--status)

[![PHP Version](https://camo.githubusercontent.com/aad484e00fb351cf0422a5593ac12c9e59674716481a53430859d4f1a3221e51/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)](https://camo.githubusercontent.com/aad484e00fb351cf0422a5593ac12c9e59674716481a53430859d4f1a3221e51/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e302532422d3737374242343f7374796c653d666f722d7468652d6261646765266c6f676f3d706870266c6f676f436f6c6f723d7768697465)[![License](https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/9218332452902d9e542a100d0af126fd3174a116456614d2cf093546a13783db/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e7376673f7374796c653d666f722d7468652d6261646765)[![Downloads](https://camo.githubusercontent.com/352dcee1e824573e03d17b6168659530b8814e6cd52a9d90d5474e6cb9795330/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d656d72616e2f7068702d746573746966793f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/352dcee1e824573e03d17b6168659530b8814e6cd52a9d90d5474e6cb9795330/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d656d72616e2f7068702d746573746966793f7374796c653d666f722d7468652d6261646765)[![Version](https://camo.githubusercontent.com/4fc33e65cf8ad2354048786b96cfdae7d03c317121adb732c9cdcf10c17ef4b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d656d72616e2f7068702d746573746966793f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/4fc33e65cf8ad2354048786b96cfdae7d03c317121adb732c9cdcf10c17ef4b9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d656d72616e2f7068702d746573746966793f7374796c653d666f722d7468652d6261646765)

**Supported PHP Versions:** 8.0, 8.1, 8.2, 8.3, 8.4

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

[](#installation)

```
composer require memran/php-testify --dev
```

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

[](#configuration)

Create `phpunit.config.php` in your project root:

```
 __DIR__ . '/vendor/autoload.php',
    'test_patterns' => [
        __DIR__ . '/tests/*Test.php',     // PHPUnit-style classes
        __DIR__ . '/tests/*_test.php',    // describe/it style
    ],
];
```

Quick Start
===========

[](#quick-start)

Create your first test file:

```
toHaveLength(3);
        expect($array)->toContain(2);
        expect($array[0])->toBe(1);
    });

    it('should allow adding elements', function() use (&$array) {
        $array[] = 4;
        expect($array)->toHaveLength(4);
        expect($array)->toContain(4);
    });
});
```

Run your tests:

```
php tests/ExampleTest.php
```

---

👀 Watch Mode
------------

[](#-watch-mode)

`php-testify` includes a **built-in watch mode** — just like Vitest or Jest — for instant feedback during development.

When enabled, it automatically re-runs your tests whenever any source or test file changes.

### 🧠 How it Works

[](#-how-it-works)

- Monitors all `.php` files in your `src/` and `tests/` directories.
- Detects file changes using a lightweight polling system (works on Windows, macOS, and Linux).
- Spawns a fresh PHP process for each re-run — ensuring a clean test environment.
- Clears the screen before each re-run and prints a banner for visibility.
- Keeps running until you stop it manually (Ctrl + C).

### ▶️ Run in Watch Mode

[](#️-run-in-watch-mode)

```
composer test -- --watch
```

Core API
--------

[](#core-api)

### Test Structure

[](#test-structure)

Organize your tests using describe blocks:

```
describe('User authentication', function() {
    describe('Login functionality', function() {
        // Tests go here
    });

    describe('Password reset', function() {
        // Tests go here
    });
});
```

Writing Tests
-------------

[](#writing-tests)

Use `test` or `it` to define individual test cases:

```
toBe(5);
expect($value)->toBeTrue();
expect($value)->toBeFalse();
expect($value)->toBeNull();
expect($value)->toBeTruthy();
expect($value)->toBeFalsy();
expect($value)->toEqual(['key' => 'value']);
expect($value)->toBeGreaterThan(10);
expect($value)->toBeLessThan(20);
expect($string)->toContain('substring');
expect($array)->toContain('item');
expect($string)->toHaveLength(10);
expect($array)->toHaveLength(5);
expect($function)->toThrow(InvalidArgumentException::class);
expect($object)->toBeInstanceOf(User::class);
```

Negative Assertions
-------------------

[](#negative-assertions)

Use `not()` for negative assertions:

```
expect($value)->not()->toBeNull();
expect($array)->not()->toContain('forbidden');
expect($string)->not()->toHaveLength(0);
```

Lifecycle Hooks
---------------

[](#lifecycle-hooks)

Set up and tear down your test environment:

```
describe('Database tests', function() {
    beforeAll(function() {
        // Runs once before all tests in this block
        setupDatabase();
    });

    afterAll(function() {
        // Runs once after all tests in this block
        cleanupDatabase();
    });

    beforeEach(function() {
        // Runs before each test
        startTransaction();
    });

    afterEach(function() {
        // Runs after each test
        rollbackTransaction();
    });

    test('database operation', function() {
        // Test that uses database
    });
});
```

Complete Example
----------------

[](#complete-example)

```
