-1

I have large api that I want to wirte api tests for each endpoint. How should I handle testing endpoints that depend on id from other endpoints?

In our application we have to create client first then branch then products then order for that branch. so if I am testing

POST /clients
POST /branches
POST /products
POST /orders

should I write create client before every test for each endpoint?

  • Alternatively you could create client record directly in database by using Db or Doctrine module. Modules for other data stores exist too. – Naktibalda Jul 21 '22 at 05:56

1 Answers1

0

You can use cURL PHP for this

Follow : https://www.php.net/manual/pt_BR/book.curl.php

Or you can run this code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com"); // API url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // for get retutn requsert
curl_setopt($ch, CURLOPT_POST, 1); // for use post requsert
curl_setopt($ch, CURLOPT_POSTFIELDS, ['key'=>'value']); // for post data
$res = curl_exec($ch); // for close requset
if (curl_error($ch)) {
    var_dump(curl_error($ch)); // for print error
} else {
    print_r($res); // for print result
}