PHPackages                             michaelhall/webunit - 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. michaelhall/webunit

ActiveProject

michaelhall/webunit
===================

Webunit test client

v2.3.0(1y ago)0167MITPHPPHP &gt;=8.0

Since Apr 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/themichaelhall/webunit)[ Packagist](https://packagist.org/packages/michaelhall/webunit)[ RSS](/packages/michaelhall-webunit/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (3)Versions (10)Used By (0)

Webunit
=======

[](#webunit)

[![Tests](https://github.com/themichaelhall/webunit/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/themichaelhall/webunit/actions)[![License](https://camo.githubusercontent.com/aa3856b5494404679ca757ed0629ed9e07a8bd013339c42652dcdf327b59d565/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c68616c6c2f776562756e69742f6c6963656e7365)](https://packagist.org/packages/michaelhall/webunit)[![Latest Stable Version](https://camo.githubusercontent.com/0a78328f8e2cfe1841d41294267bea6e88b660784c2bb5cce3b75bc65017728d/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c68616c6c2f776562756e69742f762f737461626c65)](https://packagist.org/packages/michaelhall/webunit)[![Total Downloads](https://camo.githubusercontent.com/ed8c1aa7042dbf0586ed920dca60fa80b8b4580efccd1e5fdaf39cf8dd9cf520/68747470733a2f2f706f7365722e707567782e6f72672f6d69636861656c68616c6c2f776562756e69742f646f776e6c6f616473)](https://packagist.org/packages/michaelhall/webunit)

Webunit is a command line client for automated web application tests.

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0

Install with Composer
---------------------

[](#install-with-composer)

```
$ composer require michaelhall/webunit
```

Basic usage
-----------

[](#basic-usage)

The `webunit` client requires a file in text format, containing the tests to run. Pass the name of this file as a command line parameter:

```
$ webunit testfile

```

The tests in the test file consists of one or more test cases. Every test case starts with a command. The most basic test case is just a command, e.g.

```
get https://example.org/

```

This test will be successful if the Url `https://example.org/` is functional and does not return an error or redirect status code. Otherwise, the test will fail.

The Url can also be fetched with one of the other supported HTTP methods:

```
delete https://example.org/
patch https://example.org/
post https://example.org/
put https://example.org/

```

A test case can also contain specific assertions:

```
get https://example.org/
assert-contains Example

```

Comments and whitespaces can be used to format the test file:

```
# This is a comment.
get                    https://example.org/
assert-contains        Example

# Another test case.
get                    https://example.org/foobar
assert-status-code     404

```

Some assertions can be modified with modifier characters:

```
get                    https://example.org/

# The "!" modifier negates the assertion.
# This assertion will pass if the returned status code is not 404
assert-status-code!    404

# The "^" modifier makes the assertion case insensitive.
# This assertion will pass if result contains "Example", "EXAMPLE", "eXaMpLe" etc.
assert-contains^       example

# The "~" modifier evaluates the assertion as a regular expression.
# This assertion will pass if result contains "Example" or "example".
assert-contains~       [Ee]xample

# Modifiers can be combined.
# This assertion will fail if result contains "FooBar", "foobar" etc.
assert-contains!^      foobar

```

The request can be modified with request modifiers:

```
put                    https://example.org/
with-header            Content-Type: application/json
with-raw-content       {"Foo": "Bar"}

```

The test file can set variables to be reused for the tests.

Variables are evaluated at parse-time in a manner similar to the preprocessor directives in languages like C and C#.

```
# Set the variable "Url" to the value "https://example.com".
set                    Url = https://example.com/

# get https://example.com/
get                    {{ Url }}

# get https://example.com/another-page
get                    {{ Url }}another-page

```

It is also possible to set variables from the command line:

```
$ webunit --set=Url=https://example.com/ testfile

```

```
# get https://example.com/
get                    {{ Url }}

```

A default value can be used to set the variable if not already set.

Example 1:

```
$ webunit testfile

```

```
# "Url" is not set. Set the value to "https://example.com/".
set-default            Url = https://example.com/

# get https://example.com/
get                    {{ Url }}

```

Example 2:

```
$ webunit --set=Url=https://example.org/ testfile

```

```
# "Url" is already set to "https://example.org/". Do not change it.
set-default            Url = https://example.com/

# get https://https://example.org/
get                    {{ Url }}

```

The `--no-colors` command line option can be used to disable colors in output.

```
$ webunit --no-colors testfile

```

The following escape sequences can be used in the test file:

Escape sequenceCharacter\\nLine feed\\rCarriage return\\sSpace\\tHorizontal tab\\\\Backslash```
get                    https://example.org/
assert-contains        \n\n\s

```

Commands
--------

[](#commands)

### delete *url*

[](#delete-url)

Fetches a Url via a `DELETE` request.

```
delete https://example.org/

```

### get *url*

[](#get-url)

Fetches a Url via a `GET` request.

```
get https://example.org/

```

### patch *url*

[](#patch-url)

Fetches a Url via a `PATCH` request.

```
patch https://example.org/

```

### post *url*

[](#post-url)

Fetches a Url via a `POST` request.

```
post https://example.org/

```

### put *url*

[](#put-url)

Fetches a Url via a `PUT` request.

```
put https://example.org/

```

Assertions
----------

[](#assertions)

### assert-contains *content*

[](#assert-contains-content)

Asserts that the content of the result contains the specified content. Allowed modifiers are `!`, `^`, `~`

```
assert-contains Foo

```

### assert-empty

[](#assert-empty)

Asserts that the content of the result is empty. Allowed modifier is `!`

```
assert-empty

```

### assert-equals *content*

[](#assert-equals-content)

Asserts that the content of the result is the same as the specified content. Allowed modifiers are `!`, `^`, `~`

```
assert-equals Foo

```

### assert-header *header-name\[: header-value\]*

[](#assert-header-header-name-header-value)

Asserts that the result contains a header with the specified name and an optional value. Allowed modifiers are `!`, `^`, `~`

```
assert-header Location
assert-header Location: https://example.com/

```

Note: The header name is always case-insensitive.

### assert-status-code *status-code*

[](#assert-status-code-status-code)

Asserts that the status code of the result is the same as the specified status code. Allowed modifier is `!`

Note: This assert must be present for a test to pass if the result has a status code other than 200-299.

```
assert-status-code 301

```

Request modifiers
-----------------

[](#request-modifiers)

### with-header *header-name: header-value*

[](#with-header-header-name-header-value)

Sets an HTTP-header with the specified name to the specified value.

```
with-header Accept-Language: en

```

### with-post-file *parameter-name = file-path*

[](#with-post-file-parameter-name--file-path)

Sets a POST-parameter with the specified name to a file to be uploaded. The file path can be either absolute or relative to the webunit test script. This request modifier can not be used for GET requests and can not be combined with the *with-raw-content* request modifier.

```
with-post-file File = ../../files/foo.txt

```

### with-post-parameter *parameter-name = parameter-value*

[](#with-post-parameter-parameter-name--parameter-value)

Sets a POST-parameter with the specified name to the specified value. This request modifier can not be used for GET requests and can not be combined with the *with-raw-content* request modifier.

```
with-post-parameter Text = Foo

```

### with-raw-content *content*

[](#with-raw-content-content)

Sets the request body content to the specified content. This request modifier can not be used for GET requests and can not be combined with the *with-post-file* and *with-post-parameter* request modifiers.

```
with-raw-content {"Foo": "Bar"}

```

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance42

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~303 days

Recently: every ~269 days

Total

8

Last Release

477d ago

Major Versions

v1.3.0 → v2.0.02022-10-13

PHP version history (3 changes)v1.0.0PHP &gt;=7.1

v1.2.0PHP &gt;=7.3

v2.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ed3347cc5d02108caab56932babbde07768b9e369dda328463452e17ab53ddf4?d=identicon)[michaelhall](/maintainers/michaelhall)

---

Top Contributors

[![themichaelhall](https://avatars.githubusercontent.com/u/1049696?v=4)](https://github.com/themichaelhall "themichaelhall (217 commits)")

---

Tags

unitweb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michaelhall-webunit/health.svg)

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

###  Alternatives

[twbs/bootstrap

The most popular front-end framework for developing responsive, mobile first projects on the web.

174.1k17.6M327](/packages/twbs-bootstrap)[pestphp/pest

The elegant PHP Testing Framework.

11.4k59.5M14.2k](/packages/pestphp-pest)[behat/mink

Browser controller/emulator abstraction for PHP

1.6k86.1M606](/packages/behat-mink)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[dg/bypass-finals

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

56426.3M456](/packages/dg-bypass-finals)[pestphp/pest-plugin-laravel

The Pest Laravel Plugin

22044.1M8.0k](/packages/pestphp-pest-plugin-laravel)

PHPackages © 2026

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