module-rest icon indicating copy to clipboard operation
module-rest copied to clipboard

[REST] Module does not reset client before each request

Open ihorsamusenko opened this issue 8 years ago • 8 comments

What are you trying to achieve?

I write a test which makes several request

$I->sendPOST('/my/url/test');
$I->sendGET('/my/url/test');

What do you get instead?

When I call $I->sendGET('/my/url/test'); it goes to '/my/url/my/url/test' instead of '/my/url/test'

I use REST as follows:

REST:
    depends: Symfony

ihorsamusenko avatar Nov 29 '17 11:11 ihorsamusenko

Are you sure that you haven't missed a leading / in the second request?

Naktibalda avatar Nov 29 '17 14:11 Naktibalda

Absolutely sure

ihorsamusenko avatar Nov 29 '17 14:11 ihorsamusenko

What version of Codeception are you using?

Naktibalda avatar Nov 29 '17 14:11 Naktibalda

Sorry for not providing the version at the first place. 2.3.6

ihorsamusenko avatar Nov 29 '17 15:11 ihorsamusenko

@Naktibalda any thoughts so far? I think we need to reset the client inside REST module before each sendPOST, sendGET and other send* methods.

ihorsamusenko avatar Nov 30 '17 19:11 ihorsamusenko

Works for me.

I have tried to reproduce your issue: https://github.com/Naktibalda/codeception-symfony-tests/commit/11e34fb1486b527f8aa5e23a176496d6c87fdfd1

$I->sendGET('/posts/1');
$I->seeResponseEquals('Show Post Codeception/Codeception#1');
$I->sendPOST('/doctrine/create-user',['name' => 'John']);
$I->seeResponseEquals('User created');
$I->seeCurrentUrlEquals('/doctrine/create-user');

but I got expected result:

./vendor/bin/codecept run tests/functional/SecondUriIsNotAppendedToFirstUriCept.php --steps
Codeception PHP Testing Framework v2.3.6
Powered by PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Functional Tests (1) -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Testing functional
SecondUriIsNotAppendedToFirstUriCept: 
Signature: SecondUriIsNotAppendedToFirstUriCept
Test: tests/functional/SecondUriIsNotAppendedToFirstUriCept.php
Scenario --
 I send get "/posts/1"
 I see response equals "Show Post Codeception/Codeception#1"
 I send post "/doctrine/create-user",{"name":"John"}
 I see response equals "User created"
 I see current url equals "/doctrine/create-user"
 PASSED 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Naktibalda avatar Nov 30 '17 23:11 Naktibalda

There was a similar issue report before: Codeception/Codeception#2987 But he had no leading / in uri.

Naktibalda avatar Nov 30 '17 23:11 Naktibalda

Hej there, I having the same problem like @ihorsamusenko. I wanted to test an array of different filter options for an api route. Unfortunately there seems to be an issue with sending multiple (get?) requests within one function. The response is not resetted, so the response data (and also the execution time) will be increase exponentially. The solution seems to be that all requests need to declared in a separate declared function. (And there is a leading / within the uri)

konradmichalik avatar Mar 28 '23 09:03 konradmichalik