https://github.com/rest-certain/rest-certain
PHP DSL for easy testing of REST services, with a nod to the Java DSL, REST Assured
https://github.com/rest-certain/rest-certain
api phpunit rest testing
Last synced: 3 days ago
JSON representation
PHP DSL for easy testing of REST services, with a nod to the Java DSL, REST Assured
- Host: GitHub
- URL: https://github.com/rest-certain/rest-certain
- Owner: rest-certain
- License: lgpl-3.0
- Created: 2025-04-16T17:08:09.000Z (24 days ago)
- Default Branch: main
- Last Pushed: 2025-05-06T04:27:31.000Z (4 days ago)
- Last Synced: 2025-05-06T05:25:37.226Z (4 days ago)
- Topics: api, phpunit, rest, testing
- Language: PHP
- Homepage:
- Size: 224 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: COPYING
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
REST Certain
PHP DSL for easy testing of REST services, with a nod to the Java DSL, REST Assured## About
REST Certain is a port of [REST Assured](https://github.com/rest-assured/rest-assured)
to the PHP programming language. It provides a DSL that aims to simplify and ease
the testing of REST services.This project adheres to a [code of conduct](CODE_OF_CONDUCT.md).
By participating in this project and its community, you are expected to
uphold this code.## Installation
Install this package as a development dependency using [Composer](https://getcomposer.org).
``` bash
composer require --dev rest-certain/rest-certain
```## Usage
Borrowing from the REST Assured project's examples, here's an example of how to
use REST Certain to make a `GET` request and validate a JSON response.Given the following JSON response body:
``` json
{
"lotto":{
"lottoId": 5,
"winning-numbers": [2, 45, 34, 23, 7, 5, 3],
"winners":[{
"winnerId": 23,
"numbers": [2, 45, 34, 23, 3, 5]
},{
"winnerId": 54,
"numbers": [52, 3, 12, 11, 18, 22]
}]
}
}
```We can use [JMESPath query language](https://jmespath.org) syntax to assert that
`lottoId` is equal to `5`:``` php
get('/lotto')->then()->assertThat()->bodyPath('lotto.lottoId', is(equalTo(5)));
```We can also verify all the winner IDs:
``` php
get('/lotto')->then()->assertThat()
->bodyPath('lotto.winners[*].winnerId', hasItems(54, 23));
```> [!TIP]
> REST Certain supports both [JMESPath](https://jmespath.org) and
> [JSONPath](https://www.rfc-editor.org/rfc/rfc9535). If the path query begins
> with a dollar symbol (`$`), REST Certain assumes the query syntax is JSONPath.
> Otherwise, it assumes the query syntax is JMESPath.We can also get a lot more complex and expressive with the HTTP requests and
assertions we make. For example:```php
given()
->accept('application/json')
->queryParam('foo', 'bar')
->and()->body(['name' => 'Something Cool'])
->when()
->put('/something/{id}', ['id' => 123])
->then()
->statusCode(200)
->and()->header('content-type', 'application/json')
->and()->cookie('baz', 'qux')
->and()->bodyPath('id', 123);
```REST Certain supports any HTTP method but has explicit support for `POST`, `GET`,
`PUT`, `DELETE`, `OPTIONS`, `PATCH`, and `HEAD` and includes specifying and
validating parameters, headers, cookies, and body easily.## Contributing
Contributions are welcome! To contribute, please familiarize yourself with
[CONTRIBUTING.md](CONTRIBUTING.md).## Coordinated Disclosure
Keeping user information safe and secure is a top priority, and we welcome the
contribution of external security researchers. If you believe you've found a
security issue in software that is maintained in this repository, please read
[SECURITY.md](SECURITY.md) for instructions on submitting a vulnerability report.## Copyright and License
REST Certain is copyright © [REST Certain Contributors](https://rest-certain.dev)
and licensed for use under the terms of the GNU Lesser General Public License
(LGPL-3.0-or-later) as published by the Free Software Foundation. Please see
[COPYING.LESSER](COPYING.LESSER), [COPYING](COPYING), and [NOTICE](NOTICE) for
more information.