11# JSON assertions for PHPUnit
22
3- ![ Unit tests] ( https://github.com/martin-helmich/phpunit-json-assert/workflows/Unit%20tests/badge.svg )
4- [ ![ Code Climate] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert/badges/gpa.svg )] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert )
5- [ ![ Test Coverage] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert/badges/coverage.svg )] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert/coverage )
6- [ ![ Issue Count] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert/badges/issue_count.svg )] ( https://codeclimate.com/github/martin-helmich/phpunit-json-assert )
3+ ![ Unit tests] ( https://github.com/sidz/phpunit-json-assert/workflows/Unit%20tests/badge.svg )
74
85This library adds several new assertions to [ PHPUnit] ( https://phpunit.de/ )
96that allow you to easily and concisely verify complex data structures (often,
107but not necessarily, JSON documents) using JSONPath expressions and JSON
118schemas.
129
13- ## Author and copyright
10+ ## Copyright
1411
15- Martin Helmich < kontakt@martin-helmich.de >
1612This library is [ MIT-licensed] ( LICENSE.txt ) .
1713
1814## Installation
1915
20- $ composer require --dev helmich /phpunit-json-assert
16+ $ composer require --dev sidz /phpunit-json-assert
2117
2218## Compatibility
2319
@@ -33,13 +29,13 @@ When you are using `composer require` and have already declared a dependency to
3329
3430## Usage
3531
36- Simply use the trait ` Helmich \JsonAssert\JsonAssertions` in your test case. This
32+ Simply use the trait ` Sid \JsonAssert\JsonAssertions` in your test case. This
3733trait offers a set of new ` assert* ` functions that you can use in your test
3834cases:
3935
4036``` php
4137<?php
42- use Helmich \JsonAssert\JsonAssertions;
38+ use Sid \JsonAssert\JsonAssertions;
4339use PHPUnit\Framework\TestCase;
4440
4541class MyTestCase extends TestCase
@@ -50,9 +46,9 @@ class MyTestCase extends TestCase
5046 {
5147 $jsonDocument = [
5248 'id' => 1000,
53- 'username' => 'mhelmich ',
54- 'given_name' => 'Martin ',
55- 'family_name' => 'Helmich ',
49+ 'username' => 'fakeuser ',
50+ 'given_name' => 'My ',
51+ 'family_name' => 'Name ',
5652 'age' => 27,
5753 'phones' => [
5854 'mobile' => 111,
@@ -65,7 +61,7 @@ class MyTestCase extends TestCase
6561 ]
6662 ];
6763
68- $this->assertJsonValueEquals($jsonDocument, '$.username', 'mhelmich ');
64+ $this->assertJsonValueEquals($jsonDocument, '$.username', 'fakeuser ');
6965 $this->assertJsonValueEquals($jsonDocument, '$.phones.mobile', 111);
7066 $this->assertJsonValueEquals($jsonDocument, '$.hobbies.0', 'Heavy Metal');
7167 $this->assertJsonValueEquals($jsonDocument, '$.hobbies[*]', 'Open Source Software');
@@ -81,7 +77,7 @@ Alternatively, you can use the functional interface by including the file
8177
8278``` php
8379<?php
84- use Helmich \JsonAssert\JsonAssertions;
80+ use Sid \JsonAssert\JsonAssertions;
8581use PHPUnit\Framework\TestCase;
8682
8783require_once('path/to/Functions.php');
@@ -94,9 +90,9 @@ class MyTestCase extends TestCase
9490 {
9591 $jsonDocument = [
9692 'id' => 1000,
97- 'username' => 'mhelmich ',
98- 'given_name' => 'Martin ',
99- 'family_name' => 'Helmich ',
93+ 'username' => 'fakeuser ',
94+ 'given_name' => 'My ',
95+ 'family_name' => 'Name ',
10096 'age' => 27,
10197 'hobbies' => [
10298 "Heavy Metal",
@@ -105,9 +101,9 @@ class MyTestCase extends TestCase
105101 ]
106102 ];
107103
108- assertThat($jsonDocument, containsJsonValue('$.username', 'mhelmich '));
104+ assertThat($jsonDocument, containsJsonValue('$.username', 'fakeuser '));
109105 assertThat($jsonDocument, matchesJsonConstraints([
110- '$.given_name' => 'Martin ',
106+ '$.given_name' => 'My ',
111107 '$.age' => greaterThanOrEqual(18),
112108 '$.hobbies' => callback(function($a) { return count($a) > 2; })
113109 ]));
@@ -147,7 +143,7 @@ Example:
147143
148144``` php
149145$this->assertJsonDocumentMatches($jsonDocument, [
150- '$.username' => 'mhelmich ',
146+ '$.username' => 'fakeuser ',
151147 '$.age' => PHPUnit_Framework_Assert::greaterThanOrEqual(18)
152148]);
153149```
0 commit comments