Skip to content

Update 10-APITesting.md #352

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

Merged
merged 1 commit into from
Oct 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions docs/10-APITesting.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CreateUserCest
{
$I->amHttpAuthenticated('service_user', '123456');
$I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded');
$I->sendPOST('/users', [
$I->sendPost('/users', [
'name' => 'davert',
'email' => 'davert@codeception.com'
]);
Expand Down Expand Up @@ -131,26 +131,26 @@ $I->haveHttpHeader('content-type', 'application/json');

{% endhighlight %}

When headers are set, you can send a request. To obtain data use `sendGET`:
When headers are set, you can send a request. To obtain data use `sendGet`:

{% highlight php %}

<?php
// pass in query params in second argument
$I->sendGET('/posts', [ 'status' => 'pending' ]);
$I->sendGet('/posts', [ 'status' => 'pending' ]);
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();

{% endhighlight %}

> `sendGET` won't return any value. However, you can access data from a response and perform assertions using other available methods of REST module.
> `sendGet` won't return any value. However, you can access data from a response and perform assertions using other available methods of REST module.

To create or update data you can use other common methods:

* `sendPOST`
* `sendPUT`
* `sendDELETE`
* `sendPATCH`
* `sendPost`
* `sendPut`
* `sendDelete`
* `sendPatch`

### JSON Structure Validation

Expand All @@ -159,7 +159,7 @@ If we expect a JSON response to be received we can check its structure with [JSO
{% highlight php %}

<?php
$I->sendGET('/users');
$I->sendGet('/users');
$I->seeResponseCodeIs(HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseJsonMatchesJsonPath('$[0].user.login');
Expand All @@ -173,7 +173,7 @@ You can do that by using with a [seeResponseMatchesJsonType](http://codeception.
{% highlight php %}

<?php
$I->sendGET('/users/1');
$I->sendGet('/users/1');
$I->seeResponseCodeIs(HttpCode::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseMatchesJsonType([
Expand All @@ -198,7 +198,7 @@ When you need to obtain a value from a response and use it in next requests you

<?php
list($id) = $I->grabDataFromResponseByJsonPath('$.id');
$I->sendGET('/pet/' . $id);
$I->sendGet('/pet/' . $id);

{% endhighlight %}

Expand Down Expand Up @@ -252,7 +252,7 @@ There is `seeXmlResponseIncludes` method to match inclusion of XML parts in resp
{% highlight php %}

<?php
$I->sendGET('/users.xml');
$I->sendGet('/users.xml');
$I->seeResponseCodeIs(\Codeception\Util\HttpCode::OK); // 200
$I->seeResponseIsXml();
$I->seeXmlResponseMatchesXpath('//user/login');
Expand Down Expand Up @@ -390,4 +390,4 @@ Codeception has two modules that will help you to test various web services. The


* **Next Chapter: [Codecoverage >](/docs/11-Codecoverage)**
* **Previous Chapter: [< Data](/docs/09-Data)**
* **Previous Chapter: [< Data](/docs/09-Data)**