Extract a base test case, move mock config

This commit is contained in:
Oliver Davies 2020-05-30 13:40:52 +01:00
parent 79c4d9e5fd
commit 7162438837
2 changed files with 32 additions and 17 deletions

View file

@ -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);

View 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();
}
}