PHPackages                             smeghead/single-file-unit-test - 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. smeghead/single-file-unit-test

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

smeghead/single-file-unit-test
==============================

Zero-dependency single-file unit testing framework for PHP 5.6 and above.

v0.2.1(7mo ago)111MITPHPPHP &gt;=5.6CI passing

Since Oct 17Pushed 5mo agoCompare

[ Source](https://github.com/smeghead/single-file-unit-test)[ Packagist](https://packagist.org/packages/smeghead/single-file-unit-test)[ Docs](https://github.com/smeghead/single-file-unit-test)[ RSS](/packages/smeghead-single-file-unit-test/feed)WikiDiscussions main Synced 1mo ago

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

single-file-unit-test
=====================

[](#single-file-unit-test)

[![Latest Stable Version](https://camo.githubusercontent.com/641f3b34778f88a7fea37e732bd2010eebd4aea3d2b1823d29c1aee48c4fffc7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736d6567686561642f73696e676c652d66696c652d756e69742d746573742e737667)](https://packagist.org/packages/smeghead/single-file-unit-test) [![Total Downloads](https://camo.githubusercontent.com/c17e5d2b81853c383173a0b0b67a7d00ff4e3b935eb63bcd7aa1461cd43123e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736d6567686561642f73696e676c652d66696c652d756e69742d746573742e737667)](https://packagist.org/packages/smeghead/single-file-unit-test) [![License](https://camo.githubusercontent.com/e375fb669ca5ba57b1855bf043e60e67768c8a21a6023292c55ff6c70b3721e0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736d6567686561642f73696e676c652d66696c652d756e69742d746573742e737667)](LICENSE) [![PHP Version](https://camo.githubusercontent.com/4fb9b50b39d587395c5fe377d666cab2610590dc89cadbb9fead355b344c09e7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736d6567686561642f73696e676c652d66696c652d756e69742d746573742e737667)](https://packagist.org/packages/smeghead/single-file-unit-test)

A **zero-dependency, single-file unit testing framework** for PHP 5.6 and above.
Just `require_once 'single-file-unit-test.php'` and you're ready to start testing, with a design that facilitates migration to PHPUnit.

---

Why was this created?
---------------------

[](#why-was-this-created)

This framework was born from the experience of supporting **legacy PHP projects in crisis**.

- No `composer` setup
- No framework, or custom legacy implementations
- Zero test code, making it difficult to set up a testing environment

This tool was created to meet the real-world need of "**I just want to write my first test**" in such situations.

---

Features
--------

[](#features)

- Works with just `require_once 'single-file-unit-test.php'`
- Supports `assertSame` and `expectExceptionMessage`
- Supports `setUp` and `tearDown` methods for test preparation and cleanup
- PHPUnit-compatible `TestCase` inheritance (easy migration to PHPUnit later)
- CLI execution with `php single-file-unit-test.php tests/`
- `--help` and `--version` options for help and version display
- Exit codes for success/failure determination (CI compatible)
- PHP 5.6 to 8.4 support (GitHub Actions ready)

---

Install
-------

[](#install)

Installation is **incredibly simple** - just download the single file to your project:

```
curl -o single-file-unit-test.php https://raw.githubusercontent.com/smeghead/single-file-unit-test/main/single-file-unit-test.php
```

That's it! No `composer install`, no complex setup, no dependencies to manage.
Just one command and you're ready to start testing.

---

Usage
-----

[](#usage)

### A. Using as a Library

[](#a-using-as-a-library)

```
