Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using same temp stream in multiple requests #81

Closed
JosipTrbuscic opened this issue Mar 18, 2019 · 1 comment
Closed

Using same temp stream in multiple requests #81

JosipTrbuscic opened this issue Mar 18, 2019 · 1 comment

Comments

@JosipTrbuscic
Copy link

During api testing with Codeception I tried to test multiple routes in same test using @DataProvider. If I specified 1 route, for example:

/**
 * @param FunctionalTester $
 * @param Example $example
 * @dataProvider getRoutes
 */
public function testSomeRoute(FunctionalTester $I, Example $example): void
{
    $I->expect('Data is not empty');

    $I->sendGET($example['url']);
    $data = $I->grabDataFromResponseByJsonPath('$.data')[0];

    $I->assertNotEmpty($data);
}

protected function getRoutes(): array
{
    return [
      ['url' => '/some/route'],
    ];
}

test will work as expected.

After adding 2 or more routes in data provider, for example:

protected function getRoutes(): array
{
    return [
        ['url' => '/some/route'],
        ['url' => '/some/other/route'],
        ['url' => '/example/route'],
    ];
}

second and third route test will fail because invalid json was returned.

After some debugging I found out that same php://temp stream is being used for writing response of every route. Response of the second route will be written over response of the first route and if the second response is shorter than the first, part of the first response will still be returned and fail the test because of invalid format.

@kocsismate
Copy link
Member

Hi @JosipTrbuscic ,

As I see in the referenced issue, the problem was caused by a gotcha in codeception, am I right? If so, please confirm it by closing this ticket. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants