You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After upgrading to Spectator v2, the test fails because streamedContent() returns an empty string.
Root Cause
The issue seems to originate in \Spectator\Validation\ResponseValidator. Specifically, it calls \Symfony\Component\HttpFoundation\StreamedResponse::sendContent() before \Illuminate\Testing\TestResponse::streamedContent() is invoked.
However, sendContent() should only be called once, as it consumes the stream. By the time TestResponse::streamedContent() is called, the stream has already been consumed, leaving no content for it to access.
Expected Behaviour
TestResponse::streamedContent() should return the expected streamed content, as it did in Spectator v1.
Let me know if any additional details would be helpful!
The text was updated successfully, but these errors were encountered:
Having the same issue. And just to add to this, I figured it doesn't matter if you assert valid response or not.
Also, it only fails if your actual response's Content-Type is one of the defined response types in the specification. E.g., I have 'text/csv':
content:
text/csv:
schema:
type: object
(BTW with assertValidResponse(), it will fail with 'Unable to map [text/csv] to schema type [object]', I guess because the actual type is string.)
If I comment out that text/csv part, I get my content in TestResponse::streamedContent(). I get it as well if I use any other type that is not listed in the spec. Which means it goes into ResponseValidator::streamedContent() only if Content-Type of the response matches a content type from the specification.
Thanks for the report. I did not have a lot of time lately, I'll try to look at this next week.
If somebody can open a PR with a failing test, it would save me a lot of time ! Thanks
Hello,
After upgrading Spectator to v2, I encountered an issue when using it in combination with
\Illuminate\Testing\TestResponse::streamedContent()
.Example Controller
Consider the following controller:
Corresponding Test
Here’s the test for this controller:
Observed Behaviour
streamedContent()
returns an empty string.Root Cause
The issue seems to originate in
\Spectator\Validation\ResponseValidator
. Specifically, it calls\Symfony\Component\HttpFoundation\StreamedResponse::sendContent()
before\Illuminate\Testing\TestResponse::streamedContent()
is invoked.However,
sendContent()
should only be called once, as it consumes the stream. By the timeTestResponse::streamedContent()
is called, the stream has already been consumed, leaving no content for it to access.Expected Behaviour
TestResponse::streamedContent()
should return the expected streamed content, as it did in Spectator v1.Let me know if any additional details would be helpful!
The text was updated successfully, but these errors were encountered: