glassboxx-sdk-php/tests/Glassboxx/Request/AuthTokenRequestTest.php
2020-05-30 03:04:29 +01:00

53 lines
1.6 KiB
PHP

<?php
namespace Opdavies\Glassboxx\Tests\Glassboxx\Request;
use Opdavies\Glassboxx\Config;
use Opdavies\Glassboxx\Request\AuthTokenAbstractRequest;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Contracts\HttpClient\ResponseInterface;
class AuthTokenRequestTest extends TestCase
{
public function testThatItGetsAnAuthCode(): void
{
$config = $this->getMockBuilder(Config::class)
->onlyMethods([])
->setConstructorArgs(
[
'vendor_id' => 123,
'username' => 'opdavies',
'password' => 'secret',
]
)
->getMock();
$mockRepsonse = $this->getMockBuilder(ResponseInterface::class)
->getMock();
$mockRepsonse->method('getContent')->willReturn('"abc123"');
$client = $this->getMockBuilder(MockHttpClient::class)->getMock();
$client->expects($this->once())
->method('request')
->with(
'POST',
AuthTokenAbstractRequest::BASE_URL
.AuthTokenAbstractRequest::ENDPOINT,
[
'query' => [
'password' => 'secret',
'username' => 'opdavies',
],
]
)
->willReturn($mockRepsonse);
$token = (new AuthTokenAbstractRequest($client))
->withConfig($config)
->getToken();
$this->assertSame('abc123', $token);
}
}