I have used PHPUnit for API testing. I hope this will help you.
I have just provided some sample input data for this test and validate that it will return error/success code as expected
If test hasn't got the expected return code, then it will prompt an error.
class ForgotPasswordTest extends \TestCase{
/**
* Test Forgot Password API With valid parameters
* It will check forgot password functionality with success conditions
*/
public function testForgotPasswordWithValidParameter()
{
$param=array("email"=>"shindesatishsss@gmail.com");
$response = $this->call('POST', 'forgotPassword',$param);
$data = json_decode($response->getContent(), true);
if(!isset($data["code"]))
$this->assertFalse(false);
/** check response code
* Return 600 in case if API executed successfully
*/
$this->assertEquals("600", $data["code"]);
}
/**
* Test Forgot Password API With Invalid parameters
* It will check whether you have applied user exist condition
*/
public function testForgotPasswordWithInValidParameter()
{
$param=array("email"=>"test@test.com");
$response = $this->call('POST', 'forgotPassword',$param);
$data = json_decode($response->getContent(), true);
if(!isset($data["code"]))
$this->assertFalse(false);
/** check response code
* Return 404 if user not found
*/
$this->assertEquals("404", $data["code"]);
}
/**
* Test Forgot Password API With Invalid parameters
* It will check input validations are working fine in the API
*/
public function testForgotPasswordWithInValidEmail()
{
$param=array("email"=>"satish");
$response = $this->call('POST', 'forgotPassword',$param);
$data = json_decode($response->getContent(), true);
if(!isset($data["code"]))
$this->assertFalse(false);
/** check response code
* Return 400 error code if there are some input validation error
*/
$this->assertEquals("400", $data["code"]);
}
}
You can set some other test cases also, for that just need to create new function in this class with different test cases.