-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from mnastalski/tests
Add tests
- Loading branch information
Showing
8 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- '*.x' | ||
|
||
jobs: | ||
tests: | ||
runs-on: ubuntu-22.04 | ||
|
||
strategy: | ||
matrix: | ||
php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3] | ||
|
||
name: PHP ${{ matrix.php }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
tools: composer:v2 | ||
coverage: none | ||
|
||
- name: Install composer dependencies | ||
uses: nick-invision/retry@v3 | ||
with: | ||
timeout_minutes: 5 | ||
max_attempts: 5 | ||
command: composer install --no-interaction --no-progress | ||
|
||
- name: Execute tests | ||
run: vendor/bin/phpunit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/vendor | ||
|
||
# Files | ||
.phpunit.result.cache | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true"> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
namespace Api\Response; | ||
|
||
use Baselinker\Api\Response\BaselinkerException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BaselinkerExceptionTest extends TestCase | ||
{ | ||
public function testGetters(): void | ||
{ | ||
$exception = new BaselinkerException('Message', 'CODE'); | ||
|
||
$this->assertEquals('Message', $exception->responseMessage()); | ||
$this->assertEquals('CODE', $exception->responseCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Api\Response; | ||
|
||
use Baselinker\Api\Response\BaselinkerException; | ||
use Baselinker\Api\Response\Response; | ||
use GuzzleHttp\Psr7\Response as GuzzleResponse; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ResponseTest extends TestCase | ||
{ | ||
public function testGetters(): void | ||
{ | ||
$body = json_encode([ | ||
'status' => 'SUCCESS', | ||
'list' => [ | ||
'foo' => 'bar', | ||
], | ||
]); | ||
|
||
$response = new Response( | ||
new GuzzleResponse(200, [], $body) | ||
); | ||
|
||
$this->assertEquals('{"status":"SUCCESS","list":{"foo":"bar"}}', $response->contents()); | ||
|
||
$this->assertEquals([ | ||
'status' => 'SUCCESS', | ||
'list' => [ | ||
'foo' => 'bar', | ||
], | ||
], $response->toArray()); | ||
|
||
$this->assertEquals([ | ||
'foo' => 'bar', | ||
], $response->getParameter('list')); | ||
} | ||
|
||
public function testWithErrorThrowsException(): void | ||
{ | ||
$body = json_encode([ | ||
'status' => 'ERROR', | ||
'error_code' => 'CODE', | ||
'error_message' => 'Message', | ||
]); | ||
|
||
$this->expectException(BaselinkerException::class); | ||
$this->expectExceptionMessage('[CODE] Message'); | ||
|
||
new Response( | ||
new GuzzleResponse(200, [], $body) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Baselinker\Tests\Unit; | ||
|
||
use Baselinker\Api\Request\CourierShipmentsInterface; | ||
use Baselinker\Api\Request\ExternalStoragesInterface; | ||
use Baselinker\Api\Request\OrderReturnsInterface; | ||
use Baselinker\Api\Request\OrdersInterface; | ||
use Baselinker\Api\Request\ProductCatalogInterface; | ||
use Baselinker\Baselinker; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BaselinkerTest extends TestCase | ||
{ | ||
public function testProductCatalog(): void | ||
{ | ||
$baselinker = new Baselinker([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$productCatalog = $baselinker->productCatalog(); | ||
|
||
$this->assertInstanceOf(ProductCatalogInterface::class, $productCatalog); | ||
} | ||
|
||
public function testExternalStorages(): void | ||
{ | ||
$baselinker = new Baselinker([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$externalStorages = $baselinker->externalStorages(); | ||
|
||
$this->assertInstanceOf(ExternalStoragesInterface::class, $externalStorages); | ||
} | ||
|
||
public function testOrders(): void | ||
{ | ||
$baselinker = new Baselinker([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$orders = $baselinker->orders(); | ||
|
||
$this->assertInstanceOf(OrdersInterface::class, $orders); | ||
} | ||
|
||
public function testOrderReturns(): void | ||
{ | ||
$baselinker = new Baselinker([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$orderReturns = $baselinker->orderReturns(); | ||
|
||
$this->assertInstanceOf(OrderReturnsInterface::class, $orderReturns); | ||
} | ||
|
||
public function testCourierShipments(): void | ||
{ | ||
$baselinker = new Baselinker([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$courierShipments = $baselinker->courierShipments(); | ||
|
||
$this->assertInstanceOf(CourierShipmentsInterface::class, $courierShipments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Baselinker\Tests\Unit; | ||
|
||
use Baselinker\Config; | ||
use InvalidArgumentException; | ||
use Iterator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ConfigTest extends TestCase | ||
{ | ||
public function testGetToken(): void | ||
{ | ||
$config = new Config([ | ||
'token' => 'foo', | ||
]); | ||
|
||
$this->assertEquals('foo', $config->getToken()); | ||
} | ||
|
||
/** | ||
* @dataProvider invalidConfigDataProvider | ||
*/ | ||
public function testSetWithInvalidTokenThrowsException(array $config): void | ||
{ | ||
$this->expectException(InvalidArgumentException::class); | ||
$this->expectExceptionMessage('Parameter "token" must be provided in the configuration.'); | ||
|
||
new Config($config); | ||
} | ||
|
||
public static function invalidConfigDataProvider(): Iterator | ||
{ | ||
yield 'empty config' => [ | ||
[], | ||
]; | ||
|
||
yield 'null as token' => [ | ||
[ | ||
'token' => null, | ||
] | ||
]; | ||
|
||
yield 'empty string as token' => [ | ||
[ | ||
'token' => '', | ||
] | ||
]; | ||
} | ||
} |