Skip to content

Commit cdb2d82

Browse files
committed
Merge branch 'release/3.4.0' into main
2 parents 2d35574 + 556510e commit cdb2d82

37 files changed

+3605
-70
lines changed

CHANGELOG.md

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
All notable changes to this project will be documented in this file. This project adheres to
44
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).
55

6+
## [3.4.0] - 2022-01-16
7+
8+
### Added
9+
10+
- The `assertCreatedWithServerId`, `assertCreatedWithClientId` and `assertCreatedNoContent` methods will now fail with a
11+
better assertion message if the Location header is missing.
12+
- New `assertDoesntHaveIncluded` assertion to assert that the JSON:API document does not have the top-level `included`
13+
member.
14+
- New `assertDoesntHaveMeta` assertion to assert the JSON:API document does not have the top-level `meta` member.
15+
- New `assertDoesntHaveLinks` assertion to assert the JSON:API document does not have the top-level `links` member.
16+
17+
### Fixed
18+
19+
- The `assertFetchedManyInOrder` assertion did not work if the expected `data` was an empty array.
20+
- The `assertFetchedToMany` and `assertFetchedToManyInOrder` assertions did not work if the expected `data` was an empty
21+
array.
22+
623
## [3.3.0] - 2021-07-31
724

825
### Changed
@@ -26,81 +43,95 @@ All notable changes to this project will be documented in this file. This projec
2643
## [3.2.0] - 2020-11-25
2744

2845
### Added
46+
2947
- Package now supports PHP 8.
3048

3149
## [3.1.0] - 2020-09-09
3250

3351
### Added
52+
3453
- Package now supports Laravel 8.
3554

3655
## [3.0.0] - 2020-04-12
3756

3857
### Added
58+
3959
- Package now supports PHP Unit 9.
4060

4161
### Changed
62+
4263
- Dropped support for PHP Unit 7.
4364
- Dropped support for Laravel 5.
4465

4566
## [2.1.0] - 2020-03-04
4667

4768
### Added
69+
4870
- Package now supports Laravel 7.
4971
- [#9](https://github.com/cloudcreativity/json-api-testing/issues/9)
50-
Can now assert that there are no resources included - i.e. that the `included` member is not present
51-
or is an empty list.
72+
Can now assert that there are no resources included - i.e. that the `included` member is not present or is an empty
73+
list.
5274

5375
### Fixed
76+
5477
- [#10](https://github.com/cloudcreativity/json-api-testing/pull/10)
55-
Pass expected and actual values to PHPUnit's assertion in correct order.
78+
Pass expected and actual values to PHPUnit's assertion in correct order.
5679

5780
## [2.0.0] - 2019-10-14
5881

5982
### Changed
83+
6084
- Minimum `illuminate/support` version is now `5.8` (previously `5.5`).
6185
- Minimum PHPUnit version is now `7.5` (previously `6.0`).
6286

6387
### Removed
64-
- Removed the `assertNoContent()` method from the `Concerns\HasHttpAssertions` trait. Unlike other
65-
assertion methods in that trait, this method refers to a HTTP status description which means it is
66-
likely to collide with assertions provided by frameworks. For example, Laravel `6.1.0` introduced
67-
an `assertNoContent()` method to its test response which is not compatible with the implementation
68-
provided by this package.
88+
89+
- Removed the `assertNoContent()` method from the `Concerns\HasHttpAssertions` trait. Unlike other assertion methods in
90+
that trait, this method refers to a HTTP status description which means it is likely to collide with assertions
91+
provided by frameworks. For example, Laravel `6.1.0` introduced an `assertNoContent()` method to its test response
92+
which is not compatible with the implementation provided by this package.
6993

7094
## [1.2.0] - 2019-09-04
7195

7296
### Added
97+
7398
- Package now supports Laravel 6.
7499

75100
## [1.1.0] - 2019-05-23
76101

77102
### Added
103+
78104
- Package now supports PHPUnit 8.
79105

80106
## [1.0.0] - 2019-02-27
81107

82108
### Added
109+
83110
- [#3](https://github.com/cloudcreativity/json-api-testing/issues/3)
84-
Can now assert exact errors on a document and HTTP message.
111+
Can now assert exact errors on a document and HTTP message.
85112
- [#5](https://github.com/cloudcreativity/json-api-testing/issues/5)
86-
Can now assert a server generated id with a known id.
113+
Can now assert a server generated id with a known id.
87114

88115
### Fixed
116+
89117
- [#6](https://github.com/cloudcreativity/json-api-testing/issues/6)
90-
Fixed asserting that an error exists with only an integer HTTP status code.
118+
Fixed asserting that an error exists with only an integer HTTP status code.
91119
- [#4](https://github.com/cloudcreativity/json-api-testing/issues/4)
92-
Fixed incorrect diff when asserting a resource identifier on a document that contains a resource object.
120+
Fixed incorrect diff when asserting a resource identifier on a document that contains a resource object.
93121

94122
## [1.0.0-rc.1] - 2019-01-03
95123

96124
### Added
125+
97126
- New implementation using constraint classes. Assertions are now provided via the `Assert` and `HttpAssert`
98-
classes, with traits in the `Concerns` namespace for adding these to test classes.
127+
classes, with traits in the `Concerns` namespace for adding these to test classes.
99128

100129
### Changed
130+
101131
- Minimum PHP version is now `7.1`.
102132

103133
### Removed
134+
104135
- Package no longer supports PHPUnit 5.
105136
- The previous implementation was deleted, removing these classes:
106137
- `AbstractTraversableTester`
@@ -115,34 +146,40 @@ classes, with traits in the `Concerns` namespace for adding these to test classe
115146
## [0.4.0] - 2018-04-29
116147

117148
### Added
149+
118150
- Object tester now had meta test helpers.
119151
- Can now assert the order of resources within the a resource object collection.
120152

121153
## [0.3.0] - 2018-02-08
122154

123155
### Added
156+
124157
- Now supports PHP 5.6 to 7.2.
125158
- Now supports PHPUnit 5.7 to 7.0.
126159

127160
## [0.2.0] - 2017-09-02
128161

129162
### Removed
163+
130164
- This package no longer supports PHP 5.6.
131165
- Updated to PHPUnit v6.
132166

133167
## [0.1.1] - 2017-09-02
134168

135169
### Added
170+
136171
- Can now assert that a resource object is one of multiple types using `assertTypeIs()`.
137172
- Can now assert that the `data` member of a document is `null`.
138173
- Can now assert that a resource object matches an expected structure.
139174
- Can now assert that the `data` member of a document is a resource identifier.
140175
- Can now assert that a document does not contain an `errors` member.
141176

142177
### Changed
178+
143179
- Added a generic JSON API object tester class containing common assertions.
144180

145181
### Fixed
182+
146183
- Resource object type assertion caused a PHP error.
147184

148185
## [0.1.0] - 2017-09-02

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"autoload-dev": {
3535
"psr-4": {
36-
"CloudCreativity\\JsonApi\\Testing\\": "tests/"
36+
"CloudCreativity\\JsonApi\\Testing\\Tests\\": "tests/"
3737
}
3838
},
3939
"extra": {

src/Assert.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

src/Compare.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919

2020
use Illuminate\Contracts\Routing\UrlRoutable;
2121
use Illuminate\Support\Arr;
22+
use Illuminate\Support\Collection;
2223
use SebastianBergmann\Comparator\ComparisonFailure;
2324

2425
/**
@@ -86,12 +87,13 @@ public static function resourceIdentifier($value): bool
8687
return false;
8788
}
8889

89-
$members = collect($value);
90+
$members = Collection::make($value);
9091

9192
return $members->has('type') &&
9293
$members->has('id') &&
9394
!$members->has('attributes') &&
94-
!$members->has('relationships');
95+
!$members->has('relationships') &&
96+
!$members->has('links');
9597
}
9698

9799
/**
@@ -209,7 +211,7 @@ public static function identifiers($ids, ?string $type): array
209211
return [self::identifier($ids, $type)];
210212
}
211213

212-
return collect($ids)->map(function ($id) use ($type) {
214+
return Collection::make($ids)->map(function ($id) use ($type) {
213215
return self::identifier($id, $type);
214216
})->values()->all();
215217
}
@@ -240,6 +242,10 @@ public static function identifier($id, ?string $type): array
240242
$id['id'] = (string) $id['id']->getRouteKey();
241243
}
242244

245+
if (isset($id['id']) && is_int($id['id'])) {
246+
$id['id'] = (string) $id['id'];
247+
}
248+
243249
if ($type && !array_key_exists('type', $id)) {
244250
$id['type'] = $type;
245251
}

src/Concerns/HasDocumentAssertions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

src/Concerns/HasHttpAssertions.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -47,14 +47,14 @@ trait HasHttpAssertions
4747
*/
4848
public function getDocument(): Document
4949
{
50-
if (!$this->document) {
51-
$this->document = HttpAssert::assertContent(
52-
$this->getContentType(),
53-
$this->getContent()
54-
);
50+
if ($this->document) {
51+
return $this->document;
5552
}
5653

57-
return $this->document;
54+
return $this->document = HttpAssert::assertContent(
55+
$this->getContentType(),
56+
$this->getContent()
57+
);
5858
}
5959

6060
/**
@@ -246,9 +246,7 @@ public function assertFetchedNone(): self
246246
* If either type or id are null, then it will be asserted that the data member of the content
247247
* is null.
248248
*
249-
* Prov
250-
*
251-
* @param UrlRoutable|string|int $id
249+
* @param UrlRoutable|array|string|int $id
252250
* @return $this
253251
*/
254252
public function assertFetchedToOne($id): self
@@ -505,6 +503,18 @@ public function assertIncluded(array $expected, bool $strict = true): self
505503
return $this;
506504
}
507505

506+
/**
507+
* Assert that the document does not have the top-level included member.
508+
*
509+
* @return $this
510+
*/
511+
public function assertDoesntHaveIncluded(): self
512+
{
513+
$this->getDocument()->assertNotExists('included', 'Document has included resources.');
514+
515+
return $this;
516+
}
517+
508518
/**
509519
* Assert a top-level meta response without data.
510520
*
@@ -573,6 +583,18 @@ public function assertExactMeta(array $expected, bool $strict = true): self
573583
return $this;
574584
}
575585

586+
/**
587+
* Assert that the document does not have the top-level meta member.
588+
*
589+
* @return $this
590+
*/
591+
public function assertDoesntHaveMeta(): self
592+
{
593+
$this->getDocument()->assertNotExists('meta', 'Document has top-level meta.');
594+
595+
return $this;
596+
}
597+
576598
/**
577599
* Assert that the top-level links match the expected values.
578600
*
@@ -601,6 +623,18 @@ public function assertExactLinks(array $expected, bool $strict = true): self
601623
return $this;
602624
}
603625

626+
/**
627+
* Assert that the document does not have the top-level links member.
628+
*
629+
* @return $this
630+
*/
631+
public function assertDoesntHaveLinks(): self
632+
{
633+
$this->getDocument()->assertNotExists('links', 'Document has top-level links.');
634+
635+
return $this;
636+
}
637+
604638
/**
605639
* Assert the document contains a single error that matches the supplied error.
606640
*

src/Constraints/EmptyOrMissingList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

src/Constraints/ExactInDocument.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

src/Constraints/ExactInList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

src/Constraints/HttpStatusIs.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/*
3-
* Copyright 2021 Cloud Creativity Limited
3+
* Copyright 2022 Cloud Creativity Limited
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)