2015-12-19 16:36:44 +00:00
|
|
|
<?php
|
|
|
|
|
2015-12-19 17:08:03 +00:00
|
|
|
use App\Services\RESTfulService;
|
2015-12-19 16:36:44 +00:00
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2015-12-19 17:08:03 +00:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2015-12-19 16:36:44 +00:00
|
|
|
|
|
|
|
class RESTfulAPIServiceTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions, WithoutMiddleware;
|
|
|
|
|
|
|
|
public function testUrlConstruction()
|
|
|
|
{
|
|
|
|
$api = new RESTfulService('bar', null, 'http://foo.com', \Mockery::mock(Client::class));
|
|
|
|
$this->assertEquals('http://foo.com/get/param?key=bar', $api->buildUrl('get/param'));
|
|
|
|
$this->assertEquals('http://foo.com/get/param?baz=moo&key=bar', $api->buildUrl('/get/param?baz=moo'));
|
|
|
|
$this->assertEquals('http://baz.com/?key=bar', $api->buildUrl('http://baz.com/'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRequest()
|
|
|
|
{
|
|
|
|
$client = \Mockery::mock(Client::class, [
|
|
|
|
'get' => new Response(200, [], '{"foo":"bar"}'),
|
|
|
|
'post' => new Response(200, [], '{"foo":"bar"}'),
|
|
|
|
'delete' => new Response(200, [], '{"foo":"bar"}'),
|
|
|
|
'put' => new Response(200, [], '{"foo":"bar"}'),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$api = new RESTfulService('foo', null, 'http://foo.com', $client);
|
|
|
|
|
|
|
|
$this->assertObjectHasAttribute('foo', $api->get('/'));
|
|
|
|
$this->assertObjectHasAttribute('foo', $api->post('/'));
|
|
|
|
$this->assertObjectHasAttribute('foo', $api->put('/'));
|
|
|
|
$this->assertObjectHasAttribute('foo', $api->delete('/'));
|
|
|
|
}
|
|
|
|
}
|