mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-02 08:57:32 +00:00
Extract a base test case, move mock config
This commit is contained in:
parent
79c4d9e5fd
commit
7162438837
|
@ -4,9 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Opdavies\Glassboxx\Tests\Glassboxx\Request;
|
||||
|
||||
use Opdavies\Glassboxx\Config;
|
||||
use Opdavies\Glassboxx\Request\AuthTokenRequest;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Opdavies\Glassboxx\Tests\Glassboxx\TestCase;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
|
@ -14,20 +13,9 @@ class AuthTokenRequestTest extends TestCase
|
|||
{
|
||||
public function testThatItGetsAnAuthCode(): void
|
||||
{
|
||||
$config = $this->getMockBuilder(Config::class)
|
||||
->onlyMethods([])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
'vendor_id' => 123,
|
||||
'username' => 'opdavies',
|
||||
'password' => 'secret',
|
||||
]
|
||||
)
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)
|
||||
->getMock();
|
||||
|
||||
$mockResponse = $this->getMockBuilder(ResponseInterface::class)
|
||||
->getMock();
|
||||
$mockResponse->method('getContent')->willReturn('"abc123"');
|
||||
$response->method('getContent')->willReturn('"abc123"');
|
||||
|
||||
$client = $this->getMockBuilder(MockHttpClient::class)->getMock();
|
||||
$client->expects($this->once())
|
||||
|
@ -43,10 +31,10 @@ class AuthTokenRequestTest extends TestCase
|
|||
],
|
||||
]
|
||||
)
|
||||
->willReturn($mockResponse);
|
||||
->willReturn($response);
|
||||
|
||||
$token = (new AuthTokenRequest($client))
|
||||
->withConfig($config)
|
||||
->withConfig($this->config)
|
||||
->getToken();
|
||||
|
||||
$this->assertSame('abc123', $token);
|
||||
|
|
27
tests/Glassboxx/TestCase.php
Normal file
27
tests/Glassboxx/TestCase.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Opdavies\Glassboxx\Tests\Glassboxx;
|
||||
|
||||
use Opdavies\Glassboxx\Config;
|
||||
|
||||
class TestCase extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->config = $this->getMockBuilder(Config::class)
|
||||
->onlyMethods([])
|
||||
->setConstructorArgs(
|
||||
[
|
||||
'vendor_id' => 123,
|
||||
'username' => 'opdavies',
|
||||
'password' => 'secret',
|
||||
]
|
||||
)
|
||||
->getMock();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue