Skip to content

Commit 5e05558

Browse files
committed
[Bugfix] Ensure test response content is always a string
Symfony can return a string or false for the response content. This fix ensures that false is converted to an empty string, as v4 of the JSON:API testing package type-hints the content as a string.
1 parent 5836ef9 commit 5e05558

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
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+
## Unreleased
7+
8+
### Fixed
9+
10+
- The Symfony response class can return `false` for the response content. This caused a fatal error when the content
11+
was passed to JSON:API assertions - as the assertion methods type-hint the content as a `string` in version 4 of that
12+
dependency. This has been fixed by adding a `TestResponse::getContent()` method that returns an empty string if the
13+
Symfony method returns `false`.
14+
615
## [1.1.0] - 2022-02-08
716

817
### Added

src/TestResponse.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
class TestResponse extends BaseTestResponse
2626
{
27-
2827
use HasHttpAssertions;
2928

3029
/**
@@ -79,6 +78,22 @@ public function getId(): ?string
7978
return $this->jsonApi('/data/id');
8079
}
8180

81+
/**
82+
* Get the response content.
83+
*
84+
* @return string
85+
*/
86+
public function getContent(): string
87+
{
88+
$content = $this->baseResponse->getContent();
89+
90+
if (false === $content) {
91+
return '';
92+
}
93+
94+
return $content;
95+
}
96+
8297
/**
8398
* @return string|null
8499
*/

0 commit comments

Comments
 (0)