@@ -68,10 +68,10 @@ $data = [
6868// - "id" with a numeric value,
6969// - "name" with the value "Arthur Dent", and
7070// - "options" with another associative array with the key "panic", whose value must be a boolean
71- self:: assertAssociativeArray([
72- 'id' => new IsType (IsType::TYPE_INT),
73- 'name' => new IsIdentical ('Arthur Dent'),
74- 'options' => new AssociativeArray ([ 'panic' => new IsType (IsType::TYPE_BOOL) ], true)
71+ $this-> assertAssociativeArray([
72+ 'id' => $this->isType (IsType::TYPE_INT),
73+ 'name' => $this->identicalTo ('Arthur Dent'),
74+ 'options' => $this->associativeArray ([ 'panic' => $this->isType (IsType::TYPE_BOOL) ], true)
7575], $data);
7676```
7777
@@ -109,7 +109,7 @@ $data = [
109109];
110110
111111// asserts that $data has the item `name` with the value "Arthur Dent"
112- self::ArrayHasKeyWith ('name', new IsIdentical ('Arthur Dent'), $data);
112+ $this->assertArrayHasKeyWith ('name', $this->identicalTo ('Arthur Dent'), $data);
113113```
114114
115115### Constraint ` SequentialArray `
@@ -153,7 +153,7 @@ $data = [
153153];
154154
155155// asserts that `$data` is a non-empty sequential array with non-empty items
156- self:: assertSequentialArray($data, 1, null, self:: logicalNot(new IsEmpty ()));
156+ $this-> assertSequentialArray($data, 1, null, $this-> logicalNot($this->isEmpty ()));
157157```
158158
159159### Constraint ` ArrayHasItemWith `
@@ -195,7 +195,7 @@ $data = [
195195];
196196
197197// asserts that `$data` contains "Life, the Universe and Everything" as third item (i.e. at index 2)
198- self::ArrayHasItemWith (2, new IsIdentical ("Life, the Universe and Everything" "));
198+ $this->assertArrayHasItemWith (2, $this->identicalTo ("Life, the Universe and Everything"));
199199```
200200
201201Example
@@ -207,19 +207,18 @@ declare(strict_types=1);
207207
208208namespace YourName\YourProject\Tests;
209209
210- use PHPUnit\Framework\Constraint\IsIdentical;
211210use PHPUnit\Framework\Constraint\IsType;
212211use PHPUnit\Framework\TestCase;
213212use PhrozenByte\PHPUnitArrayAsserts\ArrayAssertsTrait;
214- use PhrozenByte\PHPUnitArrayAsserts\Constraint\AssociativeArray;
215- use PhrozenByte\PHPUnitArrayAsserts\Constraint\SequentialArray;
216213
217214class MyTest extends TestCase
218215{
219216 use ArrayAssertsTrait;
220217
221218 public function testWithPHPUnitArrayAsserts(): void
222219 {
220+ // 7 lines of easy to understand code to check the API response *with* PHPUnitArrayAsserts
221+
223222 // implement your test, the result is stored in $responseData
224223
225224 $responseData = [
@@ -232,19 +231,19 @@ class MyTest extends TestCase
232231 ]
233232 ];
234233
235- $this->assertArrayHasKeyWith('users', new SequentialArray (1), $responseData);
234+ $this->assertArrayHasKeyWith('users', $this->sequentialArray (1), $responseData);
236235
237236 $this->assertAssociativeArray([
238- 'id' => new IsType (IsType::TYPE_INT),
239- 'name' => new IsIdentical ('Arthur Dent'),
240- 'options' => new AssociativeArray ([ 'panic' => new IsType (IsType::TYPE_BOOL) ], true)
237+ 'id' => $this->isType (IsType::TYPE_INT),
238+ 'name' => $this->identicalTo ('Arthur Dent'),
239+ 'options' => $this->associativeArray ([ 'panic' => $this->isType (IsType::TYPE_BOOL) ], true)
241240 ], $responseData['users'][0]);
242-
243- // 7 lines of easier to understand code to check the API response *with* PHPUnitArrayAsserts
244241 }
245242
246243 public function testWithoutPHPUnitArrayAsserts(): void
247244 {
245+ // 18 lines of pretty repetitive code to check the API response *without* PHPUnitArrayAsserts
246+
248247 // implement your test, the result is stored in $responseData
249248
250249 $responseData = [
@@ -275,8 +274,6 @@ class MyTest extends TestCase
275274
276275 $this->assertArrayHasKey('panic', $userData['options']);
277276 $this->assertIsBool($userData['options']['bool']);
278-
279- // 18 lines of pretty repetitive code to check the API response *without* PHPUnitArrayAsserts
280277 }
281278}
282279```
0 commit comments