Sample PHPUnit API Test
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Guzzle\Http\Client;
class ContactTest extends TestCase
{
private $http;
public function setUp()
{
$this->html = new Client('http://url.com');
$this->html->setDefaultOption('exceptions', false);
}
/**
* @return void
*/
public function testGetExistingContact()
{
$request = $this->html->post('/v1/contacts/46041', null, json_encode($data));
$response = $request->send();
$this->assertEquals(201, $response->getStatusCode());
}
/**
* @return void
*/
public function testGetNonExistingContact()
{
$request = $this->html->post('/v1/contacts/46041', null, json_encode($data));
$response = $request->send();
$this->assertEquals(404, $response->getStatusCode());
}
public function tearDown()
{
$this->http = null;
}
}