PHPackages                             parf/spartan-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. parf/spartan-test

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

parf/spartan-test
=================

PHP 8 Unit and Web Testing Utility

4.0.3(3w ago)871MITPHPPHP &gt;=8.0

Since Apr 1Pushed 3w ago3 watchersCompare

[ Source](https://github.com/parf/spartan-test)[ Packagist](https://packagist.org/packages/parf/spartan-test)[ RSS](/packages/parf-spartan-test/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (48)Used By (0)

Spartan Test
============

[](#spartan-test)

**PHP 8+ unit and web tests that read like PHP and run like scripts.**

Spartan Test is a small testing framework for developers who want tests to stay close to the code they exercise. A test is an ordinary PHP expression followed by its expected result, all inside a simple executable `.stest` file.

```
#!/usr/bin/env stest

; $prices = [12, 18, 30];

array_sum($prices);
    60;
```

Run it directly:

```
chmod +x price.stest
./price.stest
```

That is a complete test.

✦ What Makes It Distinctive
---------------------------

[](#-what-makes-it-distinctive)

- **▶ Tests are executable files.** Run one file directly, pass several files to `stest`, or discover a complete suite with `stest-all`.
- **↻ Expected results live beside the code.** If a result is missing, Spartan Test generates and saves it. Results stay readable, reviewable, and easy to track in Git.
- **◆ PHP remains visible.** Use normal expressions, application objects, closures, functions, exceptions, and setup code without wrapping every check in a test class.
- **◎ Unit and web tests use the same format.** Test return values, services, pages, redirects, cookies, APIs, headers, and response content from `.stest` files.
- **⚡ Repository-scale execution is built in.** `stest-all` provides discovery, file-level tags, selection filters, and high-I/O parallel execution.
- **✓ CI behavior is predictable.** Failures return nonzero, intentional skips remain successful, and infrastructure errors are not reported as passing tests.

How A Test File Works
---------------------

[](#how-a-test-file-works)

Each entry has a simple role:

```
; $user = loadUser(42);     // setup: starts with ";" in column one

$user->displayName();       // expression under test
    'Ada Lovelace';         // expected result: four-space indentation
```

Spartan Test captures:

- return values;
- thrown exceptions and errors;
- stdout from `echo` and `print`;
- PHP notices and warnings;
- web responses and request state.

When an expected result is absent, the first run adds its canonical PHP representation to the file. A later value change fails normally. Use `--generate` when updating stored results is intentional.

You can also use focused matchers when an exact value is unnecessary:

```
$responseBody;
    ~ "account created";
    ~ /request-id:\s+\w+/i;
```

Setup code supports normal PHP syntax. Multi-line PHP works as expected; only the first physical line needs the `;` setup prefix.

◎ Unit And Web Testing
----------------------

[](#-unit-and-web-testing)

Unit-style tests call PHP directly:

```
calculateTax(100, 0.2);
    20;
```

Web tests keep cookies and referrers between requests and can check pages, redirects, JSON APIs, headers, XPath results, and response content:

```
; \STest::domain('https://example.test');

/account;
    ~ "Welcome";
```

See [Web Tests](web-tests.md) for the request syntax and runnable examples.

Running Tests
-------------

[](#running-tests)

```
stest price.stest                 # run one file
stest first.stest second.stest    # run several files
stest price.stest -q              # show failures only
stest price.stest --generate      # intentionally refresh stored results
```

Use `stest-all` for a repository:

```
stest-all                         # executable .stest files
stest-all -q                      # quiet suite run
stest-all --all                   # include non-executable .stest files
stest-all --list                  # inspect the selected files
stest-all --tag="smoke -long"     # include and exclude file tags
```

By default, suite discovery skips hidden paths, `vendor`, and `node_modules`. Install [`fd`](https://github.com/sharkdp/fd) for faster discovery in large repositories; systems without it automatically use `find`. GNU Parallel powers suite execution.

Run `stest --help` or `stest-all --help` for all CLI options.

◆ Application Integration
-------------------------

[](#-application-integration)

Spartan Test searches the test directory and its parents for configuration and common bootstrap files:

- `bootstrap/autoload.php`
- `vendor/autoload.php`
- `init.php`

Use `--init=/path/to/bootstrap.php` for a one-off override, or configure your project in `stest-config.json` / `stest-config.local.json`.

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

[](#installation)

Requirements:

- PHP 8.0 or newer;
- GNU Parallel for `stest-all`;
- `fd` is optional and recommended for large repositories.

### Composer

[](#composer)

```
composer require --dev parf/spartan-test
vendor/bin/stest price.stest
vendor/bin/stest-all -q
```

### Git

[](#git)

```
mkdir -p ~/src ~/bin
git clone https://github.com/parf/spartan-test.git ~/src/spartan-test
ln -s ~/src/spartan-test/bin/stest ~/bin/stest
ln -s ~/src/spartan-test/bin/stest-all ~/bin/stest-all
```

Learn More
----------

[](#learn-more)

- [Complete syntax](Syntax.md)
- [Web testing](web-tests.md)
- [Configuration](Config.md)
- [Examples](examples/)
- [Changelog and new features](CHANGELOG)

Start with [the first test](examples/1-basics/1-first-test.stest), then explore [advanced result matching](examples/1-basics/special-tests.stest).

###  Health Score

51

—

FairBetter than 95% of packages

Maintenance95

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 97% 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

Every ~35 days

Recently: every ~2 days

Total

45

Last Release

25d ago

Major Versions

3.3.27 → 4.0.02026-07-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1048670?v=4)[Sergey Parf](/maintainers/parf)[@parf](https://github.com/parf)

---

Top Contributors

[![parf](https://avatars.githubusercontent.com/u/1048670?v=4)](https://github.com/parf "parf (130 commits)")[![mevl](https://avatars.githubusercontent.com/u/12844383?v=4)](https://github.com/mevl "mevl (2 commits)")[![glyebov](https://avatars.githubusercontent.com/u/1194182?v=4)](https://github.com/glyebov "glyebov (1 commits)")[![jusunlee](https://avatars.githubusercontent.com/u/371433?v=4)](https://github.com/jusunlee "jusunlee (1 commits)")

---

Tags

phpspartan-testtest-frameworkunit-testingutilityunit testweb test

### Embed Badge

![Health badge](/badges/parf-spartan-test/health.svg)

```
[![Health](https://phpackages.com/badges/parf-spartan-test/health.svg)](https://phpackages.com/packages/parf-spartan-test)
```

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k443.7M1.8k](/packages/nette-utils)[danielstjules/stringy

A string manipulation library with multibyte support

2.4k26.4M193](/packages/danielstjules-stringy)[voku/arrayy

Array manipulation library for PHP, called Arrayy!

4885.8M21](/packages/voku-arrayy)[mage2tv/magento-cache-clean

This package has been migrated to mage-os/magento-cache-clean. Please switch over at your convenience.

5432.2M3](/packages/mage2tv-magento-cache-clean)[vaimo/composer-patches

Applies a patch from a local or remote file to any package that is part of a given composer project. Patches can be defined both on project and on package level. Optional support for patch versioning, sequencing, custom patch applier configuration and patch command for testing/troubleshooting added patches.

3044.7M30](/packages/vaimo-composer-patches)[lodash-php/lodash-php

A port of Lodash to PHP

530776.7k5](/packages/lodash-php-lodash-php)

PHPackages © 2026

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