public function testCreate()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function () {
         return new Response(200, [], json_encode(['id' => 1, 'mode' => 'public']));
     }));
     $listsEndpoint = EndpointRegistry::get('CvoTechnologies/Twitter.Lists');
     $list = $listsEndpoint->newEntity(['mode' => 'public']);
     $this->assertInstanceOf('Muffin\\Webservice\\Model\\Resource', $listsEndpoint->save($list));
 }
 public function testSave()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function (RequestInterface $request) {
         $this->assertEquals('POST', $request->getMethod());
         $this->assertEquals('/1.1/statuses/update.json', $request->getUri()->getPath());
         $this->assertEquals(['status' => 'Hello!'], \GuzzleHttp\Psr7\parse_query($request->getBody()->getContents()));
         return new \GuzzleHttp\Psr7\Response(200, [], json_encode(['id' => 1234, 'text' => 'Hello!']));
     }));
     $statusesEndpoint = EndpointRegistry::get('CvoTechnologies/Twitter.Statuses');
     $resource = $statusesEndpoint->newEntity(['text' => 'Hello!']);
     $this->assertInstanceOf('Muffin\\Webservice\\Model\\Resource', $statusesEndpoint->save($resource));
 }
 public function testStaticCreation()
 {
     $callableCalled = $assertionCallbackCalled = false;
     $httpEmulation = HttpEmulation::fromCallable(function () use(&$callableCalled) {
         $callableCalled = true;
         return new Response();
     }, function () use(&$assertionCallbackCalled) {
         $assertionCallbackCalled = true;
     });
     $request = 'GET / HTTP/1.1' . "\r\n";
     $httpEmulation(\GuzzleHttp\Psr7\stream_for($request));
     $this->assertTrue($callableCalled);
     $this->assertTrue($assertionCallbackCalled);
 }
 public function testInitializeAccessTokenInvalid()
 {
     $invocation = 0;
     StreamWrapper::emulate(HttpEmulation::fromCallable(function (RequestInterface $request) use(&$invocation) {
         ++$invocation;
         $this->assertEquals('/oauth2/token', $request->getUri()->getPath());
         if ($invocation === 1) {
             return new Response(500);
         }
         return new Response(200, [], json_encode(['token_type' => 'bearer', 'access_token' => 'testToken']));
     }));
     $driver = new Twitter(['consumerKey' => 'consumerKey-1', 'consumerSecret' => 'consumerSecret-2']);
     $driver->initialize([]);
     $this->assertEquals('Bearer testToken', $driver->client()->config()['headers']['Authorization']);
     $this->assertEquals(2, $invocation);
 }
 public function testUsingAuth()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function () {
         return new Response();
     }));
     $client = new Client(['auth' => ['type' => 'CvoTechnologies/Twitter.Twitter']]);
     $client->get('https://example.com');
 }
 public function testDelete()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function (RequestInterface $request) {
         $this->assertEquals('POST', $request->getMethod());
         $this->assertEquals('/1.1/statuses/destroy/2.json', $request->getUri()->getPath());
         return new \GuzzleHttp\Psr7\Response(200, [], json_encode(['id' => 2, 'text' => 'Status 2?']));
     }));
     $query = new Query($this->webservice, new Endpoint(['endpoint' => 'statuses', 'connection' => $this->webservice->driver()]));
     $query->action(Query::ACTION_DELETE);
     $query->where(['id' => 2]);
     $this->assertTrue($this->webservice->execute($query));
 }
 public function testArrayAccess()
 {
     StreamWrapper::emulate(HttpEmulation::fromCallable(function (RequestInterface $request) use(&$invocations) {
         $invocations[] = $request;
         return new Response(200, [], 'test123');
     }));
     $context = fopen('https://example.com', 'r');
     $httpEmulator = stream_get_meta_data($context)['wrapper_data'];
     $this->assertTrue(isset($httpEmulator['headers']));
     $this->assertInternalType('array', $httpEmulator['headers']);
     $this->assertCount(1, $httpEmulator['headers']);
     $this->assertEquals('HTTP/1.1 200 OK', $httpEmulator['headers'][0]);
     unset($httpEmulator['headers']);
     $this->assertTrue(isset($httpEmulator['headers']));
     $httpEmulator['headers'] = [];
     $this->assertCount(1, $httpEmulator['headers']);
     fclose($context);
 }