Skip to content

FakeHttp json methods unable to create resource for request body #16

Open

Description

@vokomarov

Package version: 1.1.1.
PHP version: 8.1.

An attempt to use postJson(), putJson() of FakeHttp class instance:

$this->fakeHttp()->postJson('/', ['key' => 'value']);

Causing error:

Laminas\Diactoros\Exception\RuntimeException : Invalid stream reference provided
/Path/vendor/laminas/laminas-diactoros/src/Stream.php:344

That's because here https://github.com/spiral/testing/blob/master/src/Http/FakeHttp.php#L255 a new Laminas\Diactoros\Stream instance is creating using JSON encoded string as a $stream argument.

According Laminas\Diactoros\Stream::setStream method implementation $stream variable (which contain JSON encoded string) will be used as a file path for fopen().

A quick workaround for this issue will be to use data://text/plain, notation before JSON encoded string which will open a stream using fopen(). More here https://evertpot.com/222/

Activity

  1. self-assigned this
    on Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions