Codeception / module-rest

REST module for Codeception
MIT License
53 stars 27 forks source link

Add a generic send action #53

Closed Kolyunya closed 3 years ago

Kolyunya commented 3 years ago

Added a send() method which accepts a $method argument as a sting.

I didn't make the execute() method public in order to keep the naming consistent with the rest of the send...() methods. A also didn't rename execute() to preserve backward compatibility which will be lost otherwise.

A use-case would be to pass a request method in a data provider:

/**
 * @dataProvider provider
 */
public function test(ApiTester $I, Example $example): void
{
    $uri = 'https://example.tld/endpoint';
    $method = $example['method'];
    $data = $example['data'];

    $I->send($method, $uri, $data);
    $I->seeResponseCodeIs($example['status-code']);
}

private function provider(): array
{
    return [
        [
            'method' => 'PUT',
            'data' => [
                'foo' => 'bar',
            ],
            'status-code' => HttpCode::OK,
        ],
        [
            'method' => 'PATCH',
            'data' => [
                'foo' => 'bar',
            ],
            'status-code' => HttpCode::OK,
        ],
    ];    
}
Naktibalda commented 3 years ago

Released as 1.3.0

Kolyunya commented 3 years ago

@Naktibalda thanks for a quick release guys!