Overview

Namespaces

  • Docta
    • MercadoLibre
      • Exception
      • OAuth2
        • Client
          • Test
  • GuzzleHttp
    • Cookie
    • Exception
    • Handler
    • Promise
      • Test
      • Tests
    • Psr7
    • Test
      • Handler
    • Tests
      • CookieJar
      • Event
      • Exception
      • Handler
      • Promise
      • Psr7
  • League
    • OAuth2
      • Client
        • Grant
          • Exception
        • Provider
          • Exception
        • Test
          • Grant
          • Provider
            • Exception
            • Fake
          • Token
          • Tool
        • Token
        • Tool
  • None
  • Psr
    • Http
      • Message

Classes

  • Docta\MercadoLibre\Client
  • Docta\MercadoLibre\OAuth2\Client\Provider
  • Docta\MercadoLibre\OAuth2\Client\ResourceGeneric
  • Docta\MercadoLibre\OAuth2\Client\ResourceOwner
  • Docta\MercadoLibre\OAuth2\Client\Test\ProviderTest

Exceptions

  • Docta\MercadoLibre\Exception\ClientException
  • Overview
  • Namespace
  • Class
  • Download
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 
<?php

namespace League\OAuth2\Client\Test\Grant;

use Eloquent\Phony\Phpunit\Phony;
use GuzzleHttp\ClientInterface;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface;
use League\OAuth2\Client\Token\AccessToken;
use League\OAuth2\Client\Test\Provider\Fake as MockProvider;

abstract class GrantTestCase extends TestCase
{
    /**
     * @var \League\OAuth2\Client\Provider\AbstractProvider
     */
    protected $provider;

    protected function setUp()
    {
        $this->provider = new MockProvider(array(
            'clientId' => 'mock_client_id',
            'clientSecret' => 'mock_secret',
            'redirectUri' => 'none',
        ));
    }

    /**
     * Test that the grant's __toString method.
     */
    abstract public function testToString();

    /**
     * Data provider for access token tests.
     *
     * @return array
     */
    abstract public function providerGetAccessToken();

    /**
     * Callback to test access token request parameters.
     *
     * @return Closure
     */
    abstract protected function getParamExpectation();

    /**
     * @dataProvider providerGetAccessToken
     */
    public function testGetAccessToken($grant, array $params = [])
    {
        // Mock
        $stream = Phony::mock(StreamInterface::class);
        $stream->__toString->returns(
            '{"access_token": "mock_access_token", "expires": 3600, "refresh_token": "mock_refresh_token", "uid": 1}'
        );

        $response = Phony::mock(ResponseInterface::class);
        $response->getBody->returns($stream->get());
        $response->getHeader->with('content-type')->returns('application/json');

        $client = Phony::mock(ClientInterface::class);
        $client->send->returns($response->get());

        // Execute
        $this->provider->setHttpClient($client->get());
        $token = $this->provider->getAccessToken($grant, $params);

        // Verify
        $this->assertInstanceOf(AccessToken::class, $token);

        Phony::inOrder(
            $client->send->times(1)->calledWith(
                $this->callback(function ($request) {
                    parse_str((string) $request->getBody(), $body);
                    return call_user_func($this->getParamExpectation(), $body);
                })
            ),
            $response->getBody->times(1)->called(),
            $stream->__toString->times(1)->called(),
            $response->getHeader->times(1)->called()
        );
    }
}
MercadoLibre PHP SDK API documentation generated by ApiGen