PHPackages                             digitalzenworks/api-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. digitalzenworks/api-test

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

digitalzenworks/api-test
========================

A library for end to end testing web APIs with PHPUnit.

v1.8.39(3mo ago)196MITPHPPHP ^7.4 || ^8.0CI passing

Since Nov 29Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/jamesjohnmcguire/ApiTest)[ Packagist](https://packagist.org/packages/digitalzenworks/api-test)[ Docs](https://github.com/jamesjohnmcguire/ApiTest/)[ GitHub Sponsors](https://github.com/sponsors/jamesjohnmcguire)[ RSS](/packages/digitalzenworks-api-test/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (14)Versions (20)Used By (0)

ApiTest
=======

[](#apitest)

A library for testing web APIs with PHPUnit.

Please ⭐ star this project!

Getting Started
---------------

[](#getting-started)

### Requirements/dependencies

[](#requirementsdependencies)

- [PHP &gt;= 8.1.1](https://php.net/)

This requirement could potentially be relaxed to older version of PHP upon request.

- [php-http/guzzle7-adapter &gt;= 1.0](https://github.com/php-http/guzzle7-adapter)
- [PHPUnit &gt;= 11 || 12 || 13](https://phpunit.de/)

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

[](#installation)

### Git

[](#git)

git clone

### Composer

[](#composer)

composer require --dev

Usage:
------

[](#usage)

### API Testing

[](#api-testing)

There is one main class with one main method. You can call it like this:

```
require_once 'vendor/autoload.php';

use DigitalZenWorks\ApiTest\ApiTester;

final class UnitTests extends TestCase
{
    #[Test]
    public function ApiEndPointPostSuccess()
    {
        $data =
        [
            'name' => 'Somebody',
            'email' => 'Somebody@example.com'
        ];

        $apiTester = new APITester('https://httpbin.org');
        $testOptions = new TestOptions();
        $testOptions->tryBasicAsserts = false;

        $response =
            $this->apiTester->apiEndPointTest(
                'POST', 'https://httpbin.org/post', $data, $testOptions);

        $this->assertIsArray($response);
    }
)
```

The apiEndPointTest parameters are:

ParameterTypeParametermethodstringThe HTTP method to use.endPointstringThe API end point.data?stringThe request data.testOptionsTestOptionsA set of options.Refer to TestOptions for details.TestOptions is an object with the following properties:

PropertyDefaultDescriptioncontentRequiredtrueIndicates whethercontent is requiredin the responsebody.errorExpectedfalseIndicates whether anerror is expected.guzzleAdditionalOptionsnullAdditional Guzzleoptions to beincluded.requestDataTypenullThe data type forthe request. Can beone of the followingvalues: 'body','form\_params','json' or'multipart'.tryBasicAssertstrueIndicates whetherincluded basicassertions should betried.userAgentThe user agent toinclude inthe headers.### Page or End-to-End Testing

[](#page-or-end-to-end-testing)

This also supports testing HTML pages directly. You can call it like this:

```
require_once 'vendor/autoload.php';

use DigitalZenWorks\ApiTest\PageTester;

final class UnitTests extends TestCase
{
    #[Test]
    public function SimplePage()
    {
        PageTester $pageTester =
            new PageTester('https://httpbin.org', 'text/html', 'text/html');

        $endPoint = 'https://httpbin.org/get';

        $content = $pageTester->webPageTest('GET', $endPoint, null);

        $this->assertNotNull($content);
        $this->assertNotEmpty($content);
        $this->assertStringContainsStringIgnoringCase(
            '', $content);
    }
}
```

### Additional Examples

[](#additional-examples)

You can refer to the unit tests for additional example usage.

Additional Notes
----------------

[](#additional-notes)

This uses Guzzle to process the API request.

You can now directly access the Guzzle client with:

```
$guzzleClient = $pageTester->client;

```

### Guzzle Response Object

[](#guzzle-response-object)

You can access the Guzzle response object by accessing the public $response property of PageTester. like:

```
    $response = $pageTester->response;
    $status = $response->getStatusCode();
    $this->assertEquals(200, $status);

```

Note: Status is already checked within TestSitePage. It's just included here for the purposes of example.

### Guzzle History Object

[](#guzzle-history-object)

You can also access the Guzzle history (handler) object by accessing the public $response property of PageTester. like:

```
    $history = $pageTester->history;
    $redirects = count($history) - 1;
    $this->assertEquals(1, $redirects);

```

This can be useful for tracking redirects, among other things.

### Cookies Support

[](#cookies-support)

This now supports cookies over multiple calls. You can also access the cookies by accessing the public $cookies property of PageTester.

```
    $cookieJar = $pageTester->cookieJar;

```

### Details on `tryBasicAsserts`

[](#details-on-trybasicasserts)

If `tryBasicAsserts` is true, several basic assertions will be performed based on the provided options and response. Below is a summary of the assertions, their purposes, and the conditions under which they are applied.

AssertionDescriptionCondition`assertNotEmpty($body)`Verifies that the content body is not empty.Checked if `$contentRequired` is `true`.`assertJson($body)`Validates that the content body is valid JSON.Checked if `$jsonRequired` is `true`.`assertEquals(200, $status)`Ensures the HTTP status code is 200 (OK).Checked if `$errorExpected` is `false`.`assertNotEquals(200, $status)`Ensures the HTTP status code is not 200.Checked if `$errorExpected` is `true`.`assertArrayHasKey('error', $data)`Checks if the `error` key exists in the data array.Checked if `$errorExpected` is `true`.`assertArrayNotHasKey('error', $data)`Checks if the `error` key does not exist in the data array.Checked if `$errorExpected` is `false`.`assertTrue($errorExpected)`Verifies that `$errorExpected` is `true`.Checked during exception handling.Contributing
------------

[](#contributing)

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".

### Process:

[](#process)

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

### Coding style

[](#coding-style)

Please match the current coding style. Most notably:

1. One operation per line
2. Use complete English words in variable and method names
3. Attempt to declare variable and method names in a self-documenting manner

License
-------

[](#license)

Distributed under the MIT License. See `LICENSE` for more information.

Contact
-------

[](#contact)

James John McGuire - [@jamesmc](https://twitter.com/jamesmc) -

Project Link:

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance81

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

Recently: every ~51 days

Total

19

Last Release

101d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a9e376eda04edeaf2c673778edef648297505ea1ab769bc5c807b8f4613c4b2?d=identicon)[jamesjohnmcguire](/maintainers/jamesjohnmcguire)

---

Top Contributors

[![jamesjohnmcguire](https://avatars.githubusercontent.com/u/10033525?v=4)](https://github.com/jamesjohnmcguire "jamesjohnmcguire (152 commits)")

---

Tags

end-to-endapi-tester

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/digitalzenworks-api-test/health.svg)

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

###  Alternatives

[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2021.0M277](/packages/drupal-core-dev)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)

PHPackages © 2026

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