Skip to content

Commit 5836ef9

Browse files
committed
Merge branch 'release/1.1.0'
2 parents c5f8e2d + 9bc608c commit 5836ef9

File tree

9 files changed

+427
-31
lines changed

9 files changed

+427
-31
lines changed

.github/workflows/tests.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ jobs:
1010
build:
1111

1212
runs-on: ubuntu-latest
13-
13+
1414
strategy:
1515
fail-fast: true
1616
matrix:
17-
php: ['7.4', '8.0']
18-
laravel: ['^8.0']
17+
php: [7.4, '8.0', 8.1]
18+
laravel: [8, 9]
19+
exclude:
20+
- php: 7.4
21+
laravel: 9
1922

2023
steps:
2124
- name: Checkout Code
@@ -25,19 +28,20 @@ jobs:
2528
uses: shivammathur/setup-php@v2
2629
with:
2730
php-version: ${{ matrix.php }}
28-
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd
31+
extensions: dom, curl, libxml, mbstring, zip
2932
tools: composer:v2
3033
coverage: none
34+
ini-values: error_reporting=E_ALL
3135

3236
- name: Set Laravel Version
33-
run: composer require "laravel/framework:${{ matrix.laravel }}" --no-update -n
37+
run: composer require "illuminate/testing:^${{ matrix.laravel }}" --no-update
3438

3539
- name: Install dependencies
3640
uses: nick-invision/retry@v1
3741
with:
3842
timeout_minutes: 5
3943
max_attempts: 5
40-
command: composer install --no-suggest --prefer-dist -n -o
41-
44+
command: composer update --prefer-dist --no-interaction --no-progress
45+
4246
- name: Execute tests
4347
run: vendor/bin/phpunit

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
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+
## [1.1.0] - 2022-02-08
7+
8+
### Added
9+
10+
- Package now supports Laravel 9.
11+
- Added support for `cloudcreativity/json-api-testing` version 4.0.
12+
- Values passed to the test builder `filter()` and `page` methods can now include `UrlRoutable` objects (i.e. models).
13+
Routable objects are converted to their route key value. This also applies when a filter or page value is set via the
14+
`query()` method.
15+
16+
### Deprecated
17+
18+
- The following page assertions will be removed in the next major release. You should use the fluent methods instead to
19+
assert the resources fetched, meta and links. Deprecated methods are:
20+
- `assertFetchedPage()` - use `assertFetchedMany()`, `assertMeta()` and `assertLinks()`.
21+
- `assertFetchedPageInOrder()` - use `assertFetchedManyInOrder()`, `assertMeta()` and `assertLinks()`.
22+
- `assertFetchedEmptyPage()` - use `assertFetchedNone()`, `assertMeta()` and `assertLinks()`.
23+
624
## [1.0.0] - 2021-07-31
725

826
### Changed

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
"require": {
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
28-
"cloudcreativity/json-api-testing": "^3.3",
29-
"illuminate/http": "^8.0",
30-
"illuminate/support": "^8.0",
31-
"illuminate/testing": "^8.0"
28+
"cloudcreativity/json-api-testing": "^3.3|^4.0",
29+
"illuminate/http": "^8.0|^9.0",
30+
"illuminate/support": "^8.0|^9.0",
31+
"illuminate/testing": "^8.0|^9.0"
3232
},
3333
"require-dev": {
34-
"laravel/framework": "^8.0",
35-
"phpunit/phpunit": "^9.5"
34+
"laravel/framework": "^8.0|^9.0",
35+
"phpunit/phpunit": "^9.5.10"
3636
},
3737
"autoload": {
3838
"psr-4": {

phpunit.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
convertErrorsToExceptions="true"
99
convertNoticesToExceptions="true"
1010
convertWarningsToExceptions="true"
11+
convertDeprecationsToExceptions="true"
1112
processIsolation="false"
1213
stopOnError="false"
1314
stopOnFailure="false"
@@ -28,6 +29,7 @@
2829
</testsuite>
2930
</testsuites>
3031
<php>
32+
<ini name="error_reporting" value="E_ALL"/>
3133
<env name="DB_CONNECTION" value="testing"/>
3234
</php>
3335
</phpunit>

src/MakesJsonApiRequests.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/TestBuilder.php

Lines changed: 48 additions & 13 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.
@@ -17,21 +17,20 @@
1717

1818
namespace LaravelJsonApi\Testing;
1919

20+
use Illuminate\Contracts\Routing\UrlRoutable;
2021
use Illuminate\Support\Arr;
2122
use Illuminate\Support\Collection;
2223
use Illuminate\Support\Str;
2324
use PHPUnit\Framework\Assert;
2425
use PHPUnit\Framework\TestCase;
2526
use function array_walk_recursive;
26-
use function collect;
2727
use function implode;
2828
use function is_bool;
2929
use function is_null;
3030
use function is_scalar;
3131

3232
final class TestBuilder
3333
{
34-
3534
/**
3635
* @var TestCase|mixed
3736
*/
@@ -81,8 +80,8 @@ public function __construct($test)
8180
{
8281
$this->test = $test;
8382
$this->accept = $this->contentType = 'application/vnd.api+json';
84-
$this->query = collect();
85-
$this->headers = collect();
83+
$this->query = new Collection();
84+
$this->headers = new Collection();
8685
}
8786

8887
/**
@@ -154,7 +153,15 @@ public function asMultiPartFormData(): self
154153
*/
155154
public function query(iterable $query): self
156155
{
157-
$this->query = collect($query)->merge($query);
156+
$query = Collection::make($query);
157+
158+
foreach (['filter', 'page'] as $key) {
159+
if ($value = $query->get($key)) {
160+
$query->put($key, $this->convertIds($value));
161+
}
162+
}
163+
164+
$this->query = $this->query->merge($query);
158165

159166
return $this;
160167
}
@@ -181,7 +188,7 @@ public function includePaths(string ...$paths): self
181188
*/
182189
public function sparseFields(string $resourceType, $fieldNames): self
183190
{
184-
$this->query['fields'] = collect($this->query->get('fields'))
191+
$this->query['fields'] = Collection::make($this->query->get('fields'))
185192
->put($resourceType, implode(',', Arr::wrap($fieldNames)));
186193

187194
return $this;
@@ -195,7 +202,7 @@ public function sparseFields(string $resourceType, $fieldNames): self
195202
*/
196203
public function filter(iterable $filter): self
197204
{
198-
$this->query['filter'] = collect($filter);
205+
$this->query['filter'] = $this->convertIds($filter);
199206

200207
return $this;
201208
}
@@ -221,7 +228,7 @@ public function sort(string ...$sort): self
221228
*/
222229
public function page(iterable $page): self
223230
{
224-
$this->query['page'] = collect($page);
231+
$this->query['page'] = $this->convertIds($page);
225232

226233
return $this;
227234
}
@@ -238,7 +245,7 @@ public function withData(?iterable $data): self
238245
return $this->withJson(['data' => null]);
239246
}
240247

241-
return $this->withJson(['data' => collect($data)]);
248+
return $this->withJson(['data' => Collection::make($data)]);
242249
}
243250

244251
/**
@@ -249,7 +256,7 @@ public function withData(?iterable $data): self
249256
*/
250257
public function withJson($json): self
251258
{
252-
$this->json = collect($json);
259+
$this->json = Collection::make($json);
253260

254261
return $this;
255262
}
@@ -262,7 +269,7 @@ public function withJson($json): self
262269
*/
263270
public function withPayload($payload): self
264271
{
265-
$this->payload = collect($payload);
272+
$this->payload = Collection::make($payload);
266273

267274
return $this;
268275
}
@@ -420,10 +427,38 @@ private function buildQuery(): string
420427
*/
421428
private function buildHeaders(iterable $headers): array
422429
{
423-
return collect(['Accept' => $this->accept, 'CONTENT_TYPE' => $this->contentType])
430+
return Collection::make(['Accept' => $this->accept, 'CONTENT_TYPE' => $this->contentType])
424431
->filter()
425432
->merge($this->headers)
426433
->merge($headers)
427434
->toArray();
428435
}
436+
437+
/**
438+
* @param iterable $values
439+
* @return Collection
440+
*/
441+
private function convertIds(iterable $values): Collection
442+
{
443+
return Collection::make($values)->map(
444+
fn($value) => $this->convertId($value)
445+
);
446+
}
447+
448+
/**
449+
* @param mixed $value
450+
* @return mixed
451+
*/
452+
private function convertId($value)
453+
{
454+
if ($value instanceof UrlRoutable) {
455+
return $value->getRouteKey();
456+
}
457+
458+
if (is_iterable($value)) {
459+
return $this->convertIds($value);
460+
}
461+
462+
return $value;
463+
}
429464
}

src/TestExceptionHandler.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/TestResponse.php

Lines changed: 5 additions & 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.
@@ -125,6 +125,7 @@ public function jsonApi(string $pointer = null)
125125
* @param string|null $metaKey
126126
* @param bool $strict
127127
* @return $this
128+
* @deprecated 2.0 use `$response->assertFetchedMany($expected)->assertMeta($meta)->assertLinks($links)`.
128129
*/
129130
public function assertFetchedPage(
130131
$expected,
@@ -148,6 +149,7 @@ public function assertFetchedPage(
148149
* @param string|null $metaKey
149150
* @param bool $strict
150151
* @return $this
152+
* @deprecated 2.0 use `$response->assertFetchedManyInOrder($expected)->assertMeta($meta)->assertLinks($links)`.
151153
*/
152154
public function assertFetchedPageInOrder(
153155
$expected,
@@ -170,6 +172,7 @@ public function assertFetchedPageInOrder(
170172
* @param string|null $metaKey
171173
* @param bool $strict
172174
* @return $this
175+
* @deprecated 2.0 use `$response->assertFetchedNone()->assertMeta($meta)->assertLinks($links).
173176
*/
174177
public function assertFetchedEmptyPage(
175178
?array $links,
@@ -202,6 +205,7 @@ public function assertStatus($status)
202205
* @param bool $strict
203206
* @param bool $order
204207
* @return void
208+
* @deprecated 2.0
205209
*/
206210
private function assertPage(
207211
$expected,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy