Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.2, 8.3, 8.4, 8.5]
laravel: [11, 12, 13]
phpunit: ['10.5', '11.0']
php: [8.2, 8.3, 8.4, 8.5, 8.6]
laravel: [12, 13]
phpunit: ['11.0']
exclude:
- laravel: '13'
php: 8.2
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

### Changed

- Dropped Laravel 11, as it is end of life and not receiving security updates.

## [3.2.0] - 2026-03-28

### Added
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"php": "^8.2",
"ext-json": "*",
"cloudcreativity/json-api-testing": "^6.3",
"illuminate/http": "^11.0|^12.0|^13.0",
"illuminate/support": "^11.0|^12.0|^13.0",
"illuminate/testing": "^11.0|^12.0|^13.0"
"illuminate/http": "^12.0|^13.0",
"illuminate/support": "^12.0|^13.0",
"illuminate/testing": "^12.0|^13.0"
},
"require-dev": {
"laravel/framework": "^11.0|^12.0|^13.0",
"phpunit/phpunit": "^10.5|^11.0"
"laravel/framework": "^12.71|^13.2",
"phpunit/phpunit": "^11.5"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 16 additions & 3 deletions src/TestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ public function call(string $method, string $uri, iterable $headers = []): TestR
$headers = $this->buildHeaders($headers);

if ($this->payload) {
$payload = $this->payload->toArray();
// we need a content length as it is used by the JSON API implementation to determine if there is body.
$headers['CONTENT_LENGTH'] = $headers['CONTENT_LENGTH'] ?? mb_strlen(Arr::query($payload), '8bit');
$headers['CONTENT_LENGTH'] = $headers['CONTENT_LENGTH'] ??
mb_strlen(Arr::query($this->buildPayloadForContentLength()), '8bit');

$response = $this->test->{strtolower($method)}(
$uri,
$payload,
$this->payload->toArray(),
$headers
);
} else {
Expand Down Expand Up @@ -417,6 +417,19 @@ private function buildQuery(): string
return Arr::query($query);
}

private function buildPayloadForContentLength(): array
{
$payload = $this->payload->toArray();

array_walk_recursive($payload, function (&$value) {
if (is_object($value)) {
$value = get_object_vars($value);
}
});

return $payload;
}

/**
* @param iterable $headers
* @return array
Expand Down
15 changes: 13 additions & 2 deletions tests/Unit/TestBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Illuminate\Contracts\Routing\UrlRoutable;
use Illuminate\Foundation\Testing\Concerns\MakesHttpRequests;
use Illuminate\Http\Response;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -361,12 +362,22 @@ public function testWithJson(): void

public function testWithPayload(): void
{
$payload = ['foo' => 'bar', 'baz' => 'bat'];
$payload = [
'foo' => 'bar',
'baz' => 'bat',
'file' => $file = UploadedFile::fake()->image('avatar.jpg'),
];

$parsed = [
'foo' => 'bar',
'baz' => 'bat',
'file' => get_object_vars($file),
];

$headers = [
'Accept' => 'application/vnd.api+json',
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
'CONTENT_LENGTH' => mb_strlen(Arr::query($payload), '8bit'),
'CONTENT_LENGTH' => mb_strlen(Arr::query($parsed), '8bit'),
];

$this->mock
Expand Down