示例#1
0
 public function testGenericApi()
 {
     $api = new GenericApi(ApiInterface::MODE_MOCK);
     //can use MODE_LIVE
     $mockCallback = function () {
         return new Response(200, [], file_get_contents(__DIR__ . '/../sample/Fixtures/post1.json'));
     };
     $request = ApiRequestBuilder::create()->withMethod('get')->withUri('http://jsonplaceholder.typicode.com/posts/1')->withMock(new GenericApiMock($mockCallback))->getRequest();
     $service = new GenericApiService($request);
     $response = $api->process($service);
     static::assertEquals('200', $response->getStatusCode());
     static::assertEquals(1, json_decode($response->getBody()->getContents(), true)['id']);
 }
 public function testStaticCreate()
 {
     $rb = ApiRequestBuilder::create();
     static::assertInstanceOf(ApiRequestBuilder::class, $rb);
 }