Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Test improvement #54

Open
wants to merge 1 commit into
base: v4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"guzzlehttp/guzzle": "~6.0"
},
"require-dev": {
"phpunit/phpunit": ">=4.0.0, <6.0",
"phpunit/phpunit": "^4.8.36, <6.0",
"squizlabs/php_codesniffer": "1.5.*",
"phpmd/phpmd": "2.1.*",
"phploc/phploc": "2.0.*",
Expand Down
21 changes: 11 additions & 10 deletions tests/Component/OrderManagement/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use GuzzleHttp\Psr7\Response;
use Klarna\Rest\Transport\Method;
use Klarna\Rest\OrderManagement\Capture;
use Klarna\Rest\OrderManagement\Refund;
use Klarna\Rest\OrderManagement\Order;
use Klarna\Rest\Tests\Component\ResourceTestCase;

Expand Down Expand Up @@ -80,7 +81,7 @@ public function testFetch()
$this->assertAuthorization($request);

$capture = $order['captures'][0];
$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals($capture->getId(), $capture['capture_id']);
$this->assertEquals('1002', $capture->getId());
$this->assertEquals('data', $capture['test']);
Expand Down Expand Up @@ -262,7 +263,7 @@ public function testRefund()
$order = new Order($this->connector, '0002');
$refund = $order->refund(['data' => 'sent in']);

$this->assertInstanceOf('Klarna\Rest\OrderManagement\Refund', $refund);
$this->assertInstanceOf(Refund::class, $refund);

$request = $this->mock->getLastRequest();
$this->assertEquals(Method::POST, $request->getMethod());
Expand Down Expand Up @@ -302,7 +303,7 @@ public function testFetchRefund()
$order = new Order($this->connector, '0002');

$refund = $order->fetchRefund('refund-id-123');
$this->assertInstanceOf('Klarna\Rest\OrderManagement\Refund', $refund);
$this->assertInstanceOf(Refund::class, $refund);
$this->assertEquals(
'/ordermanagement/v1/orders/0002/refunds/refund-id-123',
$refund->getLocation()
Expand Down Expand Up @@ -357,7 +358,7 @@ public function testFetchExistingRefund()
$order->fetchRefund('refund-id-XXX');

$refund = $order->fetchRefund('refund-id-123');

$this->assertEquals('abc', $refund['test_data']);
}

Expand All @@ -376,7 +377,7 @@ public function testCreateCapture()
$order = new Order($this->connector, '0002');
$capture = $order->createCapture(['data' => 'goes here']);

$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals('http://somewhere/a-path', $capture->getLocation());

$request = $this->mock->getLastRequest();
Expand Down Expand Up @@ -418,7 +419,7 @@ public function testFetchCapture()
$order = new Order($this->connector, '0002');

$capture = $order->fetchCapture('1002');
$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals(
'/ordermanagement/v1/orders/0002/captures/1002',
$capture->getLocation()
Expand Down Expand Up @@ -461,7 +462,7 @@ public function testFetchCaptureExisting()
$order['captures'][] = $capture;

$capture = $order->fetchCapture('1002');
$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals(
'/ordermanagement/v1/orders/0002/captures/1002',
$capture->getLocation()
Expand Down Expand Up @@ -504,7 +505,7 @@ public function testFetchCaptureNew()
$order['captures'][] = $capture;

$capture = $order->fetchCapture('1003');
$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals(
'/ordermanagement/v1/orders/0002/captures/1003',
$capture->getLocation()
Expand Down Expand Up @@ -546,9 +547,9 @@ public function testFetchCaptures()
$order = new Order($this->connector, '0002');

$captures = $order->fetchCaptures();
$this->assertEquals(2, count($captures), 'Mismatched amount of captures');
$this->assertCount(2, $captures, 'Mismatched amount of captures');

$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $captures[0]);
$this->assertInstanceOf(Capture::class, $captures[0]);
$this->assertEquals(
'/ordermanagement/v1/orders/0002/captures/1001',
$captures[0]->getLocation()
Expand Down
4 changes: 2 additions & 2 deletions tests/Component/Settlements/PayoutsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testGetAllPayouts()
$payout = new Payouts($this->connector);
$data = $payout->getAllPayouts($params);

$this->assertEquals(1, count($data['payouts']));
$this->assertCount(1, $data['payouts']);
$this->assertEquals(500, $data['payouts'][0]['totals']['sale_amount']);
$this->assertEquals(10, $data['pagination']['count']);

Expand Down Expand Up @@ -165,7 +165,7 @@ public function testSummary()
$payout = new Payouts($this->connector);
$data = $payout->getSummary($params);

$this->assertEquals(2, count($data));
$this->assertCount(2, $data);
$this->assertEquals(550, $data[0]['summary_total_fee_correction_amount']);
$this->assertEquals(100, $data[1]['summary_total_fee_correction_amount']);

Expand Down
3 changes: 2 additions & 1 deletion tests/Component/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Klarna\Rest\Tests\Component;

use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
Expand All @@ -29,7 +30,7 @@
/**
* Base component test case class.
*/
class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends PHPUnitTestCase
{
const USERNAME = '1234';

Expand Down
6 changes: 4 additions & 2 deletions tests/Integration/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

namespace Klarna\Rest\Tests\Integration;

use PHPUnit\Framework\TestCase as PHPUnitTestCase;

/**
* Base unit test case class.
*/
class TestCase extends \PHPUnit\Framework\TestCase
class TestCase extends PHPUnitTestCase
{
protected $rootPath;
protected $credentials = [];
Expand All @@ -39,7 +41,7 @@ protected function setUp()
{
$this->rootPath = dirname(dirname(__DIR__));
$this->credentials = json_decode(getenv('CREDENTIALS'), true);

if (empty($this->credentials)) {
$path = $this->rootPath . '/credentials.json';
if (file_exists($path)) {
Expand Down
3 changes: 0 additions & 3 deletions tests/Unit/Checkout/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@

namespace Klarna\Tests\Unit\Rest\Checkout;

use GuzzleHttp\Exception\RequestException;
use Klarna\Rest\Checkout\Order;
use Klarna\Rest\Transport\Method;
use Klarna\Rest\Tests\Unit\TestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\Exception\ConnectorException;

/**
* Unit test cases for the checkout order resource.
Expand Down
5 changes: 1 addition & 4 deletions tests/Unit/OrderManagement/CaptureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@

namespace Klarna\Tests\Unit\Rest\OrderManagement;

use GuzzleHttp\Exception\RequestException;
use Klarna\Rest\OrderManagement\Capture;
use Klarna\Rest\Tests\Unit\TestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\Method;
use Klarna\Rest\Transport\Exception\ConnectorException;

/**
* Unit test cases for the capture resource.
Expand Down Expand Up @@ -227,7 +224,7 @@ public function testCreateInvalidStatusCode()
$this->response->expects($this->any())
->method('getStatus')
->will($this->returnValue('204'));

$capture = new Capture($this->connector, '/orders/1');

$this->setExpectedException(
Expand Down
7 changes: 2 additions & 5 deletions tests/Unit/OrderManagement/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@

namespace Klarna\Tests\Unit\Rest\OrderManagement;

use GuzzleHttp\Exception\RequestException;
use Klarna\Rest\OrderManagement\Capture;
use Klarna\Rest\OrderManagement\Order;
use Klarna\Rest\Tests\Unit\TestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\Method;
use Klarna\Rest\Transport\Exception\ConnectorException;

/**
* Unit test cases for the order resource.
Expand Down Expand Up @@ -691,7 +688,7 @@ public function testFetchCapture()
$order = new Order($this->connector, '12345');
$capture = $order->fetchCapture('2');

$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals('from response json', $capture['data']);
}

Expand Down Expand Up @@ -776,7 +773,7 @@ public function testFetchCaptureNoCache()

$capture = $order->fetchCapture('2');

$this->assertInstanceOf('Klarna\Rest\OrderManagement\Capture', $capture);
$this->assertInstanceOf(Capture::class, $capture);
$this->assertEquals('from response json', $capture['data']);
$this->assertEquals('2', $capture->getId());
}
Expand Down
6 changes: 1 addition & 5 deletions tests/Unit/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,9 @@
namespace Klarna\Rest\Tests\Unit;

use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\RequestException;
use Klarna\Rest\Tests\Unit\TestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\Exception\ConnectorException;
use Klarna\Rest\Transport\UserAgent;
use Klarna\Rest\Resource;
use GuzzleHttp\Psr7\Response;

/**
* Unit test cases for the resource class.
Expand Down Expand Up @@ -109,7 +105,7 @@ public function testLocation()
{
$r = $this->getMockForAbstractClass('Klarna\Rest\Resource', [$this->connector]);
$this->assertEquals(null, $r->getLocation());

$r->setLocation('/new/location');
$this->assertEquals('/new/location', $r->getLocation());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@

namespace Klarna\Rest\Tests\Unit;

use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\ApiResponse;

/**
* Base unit test case class.
*/
class TestCase extends \PHPUnit_Framework_TestCase
class TestCase extends PHPUnitTestCase
{
/**
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Transport/ApiResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

namespace Klarna\Rest\Tests\Unit\Transport;

use PHPUnit\Framework\TestCase;
use Klarna\Rest\Transport\ApiResponse;

/**
* Unit test cases for the UserAgent class.
*/
class ApiResponseTest extends \PHPUnit_Framework_TestCase
class ApiResponseTest extends TestCase
{
/**
* Make sure the default user agent components are present.
Expand Down
6 changes: 2 additions & 4 deletions tests/Unit/Transport/Exception/ConnectorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

namespace Klarna\Rest\Tests\Unit\Transport\Exception;

use GuzzleHttp\Exception\RequestException;
use PHPUnit\Framework\TestCase;
use Klarna\Rest\Transport\Exception\ConnectorException;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
* Unit test cases for the ConnectorException.
*/
class ConnectorExceptionTest extends \PHPUnit_Framework_TestCase
class ConnectorExceptionTest extends TestCase
{
/**
* Make sure the getters work as intended.
Expand Down
7 changes: 3 additions & 4 deletions tests/Unit/Transport/GuzzleConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use GuzzleHttp\Exception\RequestException;
use Klarna\Rest\Tests\Unit\TestCase;
use Klarna\Rest\Transport\Connector;
use Klarna\Rest\Transport\Exception\ConnectorException;
use Klarna\Rest\Transport\UserAgent;

/**
Expand Down Expand Up @@ -259,7 +258,7 @@ public function testCreate()
);

$client = $connector->getClient();
$this->assertInstanceOf('GuzzleHttp\ClientInterface', $client);
$this->assertInstanceOf(ClientInterface::class, $client);

$this->assertEquals(self::BASE_URL, $client->getConfig('base_uri'));

Expand All @@ -283,7 +282,7 @@ public function testCreateDefaultUserAgent()
);

$userAgent = $connector->getUserAgent();
$this->assertInstanceOf('Klarna\Rest\Transport\UserAgent', $userAgent);
$this->assertInstanceOf(UserAgent::class, $userAgent);
$this->assertContains('Library/Klarna.kco_rest_php', strval($userAgent));
}

Expand All @@ -296,7 +295,7 @@ public function testGetClient()
{
$client = $this->object->getClient();

$this->assertInstanceOf('GuzzleHttp\ClientInterface', $client);
$this->assertInstanceOf(ClientInterface::class, $client);
$this->assertSame($this->client, $client);
}
}
3 changes: 2 additions & 1 deletion tests/Unit/Transport/ResponseValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@

namespace Klarna\Rest\Tests\Unit\Transport;

use PHPUnit\Framework\TestCase;
use Klarna\Rest\Transport\ResponseValidator;
use Klarna\Rest\Transport\ApiResponse;
use Psr\Http\Message\ResponseInterface;

/**
* Unit test cases for the ResponseValidator class.
*/
class ResponseValidatorTest extends \PHPUnit_Framework_TestCase
class ResponseValidatorTest extends TestCase
{
/**
* @var ResponseInterface
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Transport/UserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@

namespace Klarna\Rest\Tests\Unit\Transport;

use PHPUnit\Framework\TestCase;
use Klarna\Rest\Transport\UserAgent;

/**
* Unit test cases for the UserAgent class.
*/
class UserAgentTest extends \PHPUnit_Framework_TestCase
class UserAgentTest extends TestCase
{
/**
* @var UserAgent
Expand Down