Skip to content

Commit

Permalink
Merge pull request #40 from xvilo/update-packages
Browse files Browse the repository at this point in the history
Update packages
  • Loading branch information
xvilo authored Feb 24, 2024
2 parents 770ee64 + 0fc1127 commit b9dccc0
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 197 deletions.
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
"php-http/client-common": "^2.6",
"php-http/discovery": "^1.14",
"lcobucci/jwt": "^4.2 || ^5.0",
"symfony/serializer": "^5.4 || ^6.2",
"symfony/var-dumper": "^6.3"
"symfony/serializer": "^5.4 || ^6.4 || ^7.0",
"symfony/var-dumper": "^5.4 || ^6.4 || ^7.0"
},
"require-dev": {
"phpstan/phpstan": "^1.9",
"rector/rector": "^0.15.2 || ^0.16.0 || ^0.17.0 || ^0.18.0",
"nyholm/psr7": "^1.5",
"symfony/http-client": "^6.2",
"symfony/http-client": "^5.4 || ^6.4 || ^7.0",
"phpunit/phpunit": "^10.0",
"symfony/property-access": "^5.4 || ^6.2",
"symfony/property-access": "^5.4 || ^6.4 || ^7.0",
"friendsofphp/php-cs-fixer": "^3.13",
"ramsey/uuid": "^4.7"
"ramsey/uuid": "^4.7",
"rector/rector": "^1.0",
"phpstan/phpstan": "^1.10"
},
"config": {
"allow-plugins": {
Expand Down
17 changes: 1 addition & 16 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ parameters:
count: 1
path: src/Api/AbstractApi.php

-
message: "#^Method Xvilo\\\\OVpayApi\\\\Api\\\\AbstractApi\\:\\:post\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/Api/AbstractApi.php

-
message: "#^Method Xvilo\\\\OVpayApi\\\\Api\\\\AbstractApi\\:\\:postRaw\\(\\) has parameter \\$requestHeaders with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -46,7 +41,7 @@ parameters:
path: src/Api/AbstractApi.php

-
message: "#^Variable \\$parameters in empty\\(\\) always exists and is not falsy\\.$#"
message: "#^Strict comparison using \\=\\=\\= between non\\-empty\\-array and array\\{\\} will always evaluate to false\\.$#"
count: 1
path: src/Api/AbstractApi.php

Expand All @@ -65,11 +60,6 @@ parameters:
count: 1
path: src/Models/Receipt.php

-
message: "#^Method Xvilo\\\\OVpayApi\\\\Tests\\\\Functional\\\\Api\\\\AnonymousApiTest\\:\\:registrationOpenDataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Functional/Api/AnonymousApiTest.php

-
message: "#^Method Xvilo\\\\OVpayApi\\\\Tests\\\\Functional\\\\TestCase\\:\\:getMockHttpClient\\(\\) has parameter \\$responseFactory with no value type specified in iterable type iterable\\.$#"
count: 1
Expand All @@ -90,11 +80,6 @@ parameters:
count: 2
path: tests/Unit/Authentication/TokenMethodTest.php

-
message: "#^Method Xvilo\\\\OVpayApi\\\\Tests\\\\Unit\\\\Authentication\\\\TokenMethodTest\\:\\:tokenExpiredDataProvider\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: tests/Unit/Authentication/TokenMethodTest.php

-
message: "#^Parameter \\#1 \\$token of class Xvilo\\\\OVpayApi\\\\Authentication\\\\TokenMethod constructor expects Lcobucci\\\\JWT\\\\Token, Lcobucci\\\\JWT\\\\Token\\|PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
count: 4
Expand Down
8 changes: 5 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\ValueObject\PhpVersion;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\PHPUnit\Set\PHPUnitLevelSetList;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

Expand All @@ -21,7 +21,9 @@
SetList::CODING_STYLE,
SetList::DEAD_CODE,
SetList::TYPE_DECLARATION,
PHPUnitLevelSetList::UP_TO_PHPUNIT_100
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
]);

$rectorConfig->skip([
Expand Down
6 changes: 2 additions & 4 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ protected function get(string $path, array $parameters = [], array $requestHeade
* @param string $path request path
* @param array $parameters POST parameters to be JSON encoded
* @param array $requestHeaders request headers
*
* @return array|string
*/
protected function post(string $path, array $parameters = [], array $requestHeaders = [])
protected function post(string $path, array $parameters = [], array $requestHeaders = []): string
{
return $this->postRaw(
$path,
Expand Down Expand Up @@ -89,6 +87,6 @@ protected function delete(string $path, array $parameters = [], array $requestHe
*/
protected function createJsonBody(array $parameters): ?string
{
return ($parameters === []) ? null : json_encode($parameters, empty($parameters) ? JSON_FORCE_OBJECT : 0);
return ($parameters === []) ? null : json_encode($parameters, $parameters === [] ? JSON_FORCE_OBJECT : 0);
}
}
12 changes: 6 additions & 6 deletions src/HttpClient/HttpClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use Http\Client\Common\HttpMethodsClient;
use Http\Client\Common\Plugin;
use Http\Client\Common\PluginClientFactory;
use Http\Client\HttpClient;
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\Psr17FactoryDiscovery;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;

class HttpClientBuilder
{
private readonly HttpClient $httpClient;
private readonly ClientInterface $httpClient;

private readonly RequestFactoryInterface $requestFactory;

Expand All @@ -27,9 +27,9 @@ class HttpClientBuilder
private ?HttpMethodsClient $pluginClient = null;

public function __construct(
HttpClient $httpClient = null,
RequestFactoryInterface $requestFactory = null,
StreamFactoryInterface $streamFactory = null
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
?StreamFactoryInterface $streamFactory = null
) {
$this->httpClient = $httpClient ?: HttpClientDiscovery::find();
$this->requestFactory = $requestFactory ?: Psr17FactoryDiscovery::findRequestFactory();
Expand Down Expand Up @@ -66,7 +66,7 @@ public function removePlugin($fqcn): self

public function getHttpClient(): HttpMethodsClient
{
if (!isset($this->pluginClient)) {
if (!$this->pluginClient instanceof HttpMethodsClient) {
$plugins = $this->plugins;
$this->pluginClient = new HttpMethodsClient(
(new PluginClientFactory())->createClient($this->httpClient, $plugins),
Expand Down
2 changes: 1 addition & 1 deletion src/HttpClient/Plugin/ExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
}

if ($response->getStatusCode() === 403) {
if ((isset($content['title']) || isset($content['detail']))) {
if (isset($content['title']) || isset($content['detail'])) {
throw new ApiForbiddenException(sprintf('%s %s', $content['title'] ?? '', $content['detail'] ?? ''));
}

Expand Down
73 changes: 36 additions & 37 deletions tests/Functional/Api/AnonymousApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Xvilo\OVpayApi\Models\CorrectionOptions;
use Xvilo\OVpayApi\Models\Notices;
use Xvilo\OVpayApi\Tests\Functional\TestCase;
use Iterator;

final class AnonymousApiTest extends TestCase
{
Expand All @@ -19,19 +20,19 @@ public function testGetNotices(): void
);

$res = $apiClient->anonymous()->getNotices();
self::assertInstanceOf(Notices::class, $res);
self::assertIsArray($res->getServiceWebsiteDisruptions());
self::assertIsArray($res->getOvPayAppDisruptions());
self::assertEmpty($res->getServiceWebsiteDisruptions());
self::assertEmpty($res->getOvPayAppDisruptions());
$this->assertInstanceOf(Notices::class, $res);
$this->assertIsArray($res->getServiceWebsiteDisruptions());
$this->assertIsArray($res->getOvPayAppDisruptions());
$this->assertEmpty($res->getServiceWebsiteDisruptions());
$this->assertEmpty($res->getOvPayAppDisruptions());

self::assertInstanceOf(Notices\TermsAndConditions::class, $res->getTermsAndConditions());
self::assertEquals([], $res->getTermsAndConditions()->getHighlights());
self::assertInstanceOf(DateTimeImmutable::class, $res->getTermsAndConditions()->getLastModified());
$this->assertInstanceOf(Notices\TermsAndConditions::class, $res->getTermsAndConditions());
$this->assertSame([], $res->getTermsAndConditions()->getHighlights());
$this->assertInstanceOf(DateTimeImmutable::class, $res->getTermsAndConditions()->getLastModified());

self::assertInstanceOf(Notices\PrivacyStatement::class, $res->getPrivacyStatement());
self::assertInstanceOf(DateTimeImmutable::class, $res->getPrivacyStatement()->getLastModified());
self::assertEquals([], $res->getPrivacyStatement()->getHighlights());
$this->assertInstanceOf(Notices\PrivacyStatement::class, $res->getPrivacyStatement());
$this->assertInstanceOf(DateTimeImmutable::class, $res->getPrivacyStatement()->getLastModified());
$this->assertSame([], $res->getPrivacyStatement()->getHighlights());
}

#[\PHPUnit\Framework\Attributes\DataProvider('registrationOpenDataProvider')]
Expand All @@ -40,47 +41,45 @@ public function testIsRegistrationOpen(string $data, bool $expected): void
$apiClient = $this->getApiClientWithHttpClient(
$this->getMockHttpClient(new MockResponse($data))
);
self::assertEquals($expected, $apiClient->anonymous()->isRegistrationOpen());
$this->assertEquals($expected, $apiClient->anonymous()->isRegistrationOpen());
}

public static function registrationOpenDataProvider(): array
public static function registrationOpenDataProvider(): Iterator
{
return [
'bare-true' => ['data' => 'true', 'expected' => true],
'true-in-array' => ['data' => '[true]', 'expected' => true],
'bare-false' => ['data' => 'false', 'expected' => false],
'false-in-array' => ['data' => '[false]', 'expected' => false],
'random' => ['data' => '{"foo": "bar"}', 'expected' => false],
];
yield 'bare-true' => ['data' => 'true', 'expected' => true];
yield 'true-in-array' => ['data' => '[true]', 'expected' => true];
yield 'bare-false' => ['data' => 'false', 'expected' => false];
yield 'false-in-array' => ['data' => '[false]', 'expected' => false];
yield 'random' => ['data' => '{"foo": "bar"}', 'expected' => false];
}

public function testGetReceipt(): void
{
$apiClient = $this->getApiClientWithHttpClient($this->getMockHttpClient(new MockResponse($this->getAnonymousReceiptResponse())));

$res = $apiClient->anonymous()->getReceipt('ABCD', 0000);
self::assertCount(1, $res->getRelatedPayments());
self::assertCount(4, $res->getRelatedTrips());
self::assertCount(0, $res->getRelatedBalances());
self::assertNull($res->getToken());
$this->assertCount(1, $res->getRelatedPayments());
$this->assertCount(4, $res->getRelatedTrips());
$this->assertCount(0, $res->getRelatedBalances());
$this->assertNull($res->getToken());

foreach ($res->getRelatedTrips() as $relatedTrip) {
if ($relatedTrip->getTrip()->getId() === 130788476) {
$correctionOptions = $relatedTrip->getCorrectionOptions();
self::assertInstanceOf(CorrectionOptions::class, $correctionOptions);
self::assertEquals('CorrectableNoStops', $correctionOptions->getCorrectableStatus());
self::assertInstanceOf(DateTimeImmutable::class, $correctionOptions->getCorrectionWindowEnd());
self::assertInstanceOf(DateTimeImmutable::class, $correctionOptions->getCorrectionWindowStart());
self::assertTrue($correctionOptions->isOnboardValidation());
self::assertIsArray($correctionOptions->getStops());
self::assertCount(1, $correctionOptions->getStops());
$this->assertInstanceOf(CorrectionOptions::class, $correctionOptions);
$this->assertSame('CorrectableNoStops', $correctionOptions->getCorrectableStatus());
$this->assertInstanceOf(DateTimeImmutable::class, $correctionOptions->getCorrectionWindowEnd());
$this->assertInstanceOf(DateTimeImmutable::class, $correctionOptions->getCorrectionWindowStart());
$this->assertTrue($correctionOptions->isOnboardValidation());
$this->assertIsArray($correctionOptions->getStops());
$this->assertCount(1, $correctionOptions->getStops());

self::assertEquals('45526', $correctionOptions->getStops()[0]->getPrivateCode());
self::assertCount(2, $correctionOptions->getStops()[0]->getLocalizedNames());
self::assertEquals('nl-NL', $correctionOptions->getStops()[0]->getLocalizedNames()[0]->getLanguage());
self::assertEquals('City 1, Stop 2', $correctionOptions->getStops()[0]->getLocalizedNames()[0]->getText());
self::assertEquals('en-US', $correctionOptions->getStops()[0]->getLocalizedNames()[1]->getLanguage());
self::assertEquals('City 1, Stop 2', $correctionOptions->getStops()[0]->getLocalizedNames()[1]->getText());
$this->assertSame('45526', $correctionOptions->getStops()[0]->getPrivateCode());
$this->assertCount(2, $correctionOptions->getStops()[0]->getLocalizedNames());
$this->assertSame('nl-NL', $correctionOptions->getStops()[0]->getLocalizedNames()[0]->getLanguage());
$this->assertSame('City 1, Stop 2', $correctionOptions->getStops()[0]->getLocalizedNames()[0]->getText());
$this->assertSame('en-US', $correctionOptions->getStops()[0]->getLocalizedNames()[1]->getLanguage());
$this->assertSame('City 1, Stop 2', $correctionOptions->getStops()[0]->getLocalizedNames()[1]->getText());
}
}
}
Expand Down
20 changes: 8 additions & 12 deletions tests/Functional/Api/PassengerAccountsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Xvilo\OVpayApi\Exception\ApiResourceNotFound;
use Xvilo\OVpayApi\Exception\UnauthorizedException;
use Xvilo\OVpayApi\Tests\Functional\TestCase;
use Iterator;

final class PassengerAccountsApiTest extends TestCase
{
Expand All @@ -24,7 +25,7 @@ public function testAddSuccessfulMatch(): void
$apiClient->Authenticate(new HeaderMethod('Authorization', 'Bearer TEST'));

$resp = $apiClient->passengerAccounts()->addByServiceReferenceId('1234567ABCDEF', 1445);
self::assertEquals($returnUUid, $resp->getPaymentExternalBackOfficeToken());
$this->assertEquals($returnUUid, $resp->getPaymentExternalBackOfficeToken());
}

public function testUnsuccessfulMatch(): void
Expand All @@ -45,7 +46,7 @@ public function testUnsuccessfulMatch(): void

public function testUnauthenticatedRequest(): void
{
$returnUUid = UUid::uuid4();
$returnUUid = Uuid::uuid4();
$paymentServiceReferenceId = 'NLOV1234567ABCDEFG';
$amountInCents = 4830;
$apiClient = $this->getApiClientWithHttpClient($this->getMockHttpClient(
Expand Down Expand Up @@ -84,7 +85,7 @@ public function testDeletePassengerAccount(): void
$apiClient->Authenticate(new HeaderMethod('Authorization', 'Bearer TEST'));

$resp = $apiClient->passengerAccounts()->deletePassengerAccount($cardXtat->toString());
self::assertTrue($resp);
$this->assertTrue($resp);
}

public function testDeleteRandomPassengerAccount(): void
Expand Down Expand Up @@ -119,15 +120,10 @@ static function ($method, $url, $options) use ($expected): \Symfony\Component\Ht
$apiClient->passengerAccounts()->addByServiceReferenceId($paymentServiceReferenceId, 2023);
}

/**
* @return array<string, array<int, string>>
*/
public static function paymentServiceReferenceIdProvider(): array
public static function paymentServiceReferenceIdProvider(): Iterator
{
return [
'Correct clean' => ['12345ABCDEF', 'NLOV12345ABCDEF'],
'No clean needed' => ['12345ABCDEF', '12345ABCDEF'],
'Only clean at beginning' => ['12345NLOVEF', '12345NLOVEF'],
];
yield 'Correct clean' => ['12345ABCDEF', 'NLOV12345ABCDEF'];
yield 'No clean needed' => ['12345ABCDEF', '12345ABCDEF'];
yield 'Only clean at beginning' => ['12345NLOVEF', '12345NLOVEF'];
}
}
28 changes: 14 additions & 14 deletions tests/Functional/Api/PaymentApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function testGetPayments(): void

$result = $apiClient->payment()->getPayments('2af820fb-30a4-48fe-881e-21521c94a95e');

self::assertInstanceOf(Payments::class, $result);
self::assertTrue($result->isEndOfListReached());
self::assertEquals(3, $result->getOffset());
self::assertNotEmpty($result->getItems());
self::assertCount(1, $result->getItems());
self::assertInstanceOf(Payment::class, $result->getItems()[0]);
$this->assertInstanceOf(Payments::class, $result);
$this->assertTrue($result->isEndOfListReached());
$this->assertSame(3, $result->getOffset());
$this->assertNotEmpty($result->getItems());
$this->assertCount(1, $result->getItems());
$this->assertInstanceOf(Payment::class, $result->getItems()[0]);
}

public function testGetPaymentsNoAuth(): void
Expand All @@ -53,16 +53,16 @@ public function testGetReceipt(): void
$apiClient->Authenticate(new HeaderMethod('Authorization', 'Bearer TEST'));

$result = $apiClient->payment()->getReceipt('f7386e11-1142-47a9-bf61-39ac6825588e', 'EVENT-O12-12345678901234567890123456789');
self::assertNotEmpty($result->getRelatedPayments());
self::assertCount(1, $result->getRelatedPayments());
self::assertInstanceOf(Payment::class, $result->getRelatedPayments()[0]);
$this->assertNotEmpty($result->getRelatedPayments());
$this->assertCount(1, $result->getRelatedPayments());
$this->assertInstanceOf(Payment::class, $result->getRelatedPayments()[0]);

self::assertNotEmpty($result->getRelatedTrips());
self::assertCount(1, $result->getRelatedTrips());
self::assertInstanceOf(ReceiptTrip::class, $result->getRelatedTrips()[0]);
$this->assertNotEmpty($result->getRelatedTrips());
$this->assertCount(1, $result->getRelatedTrips());
$this->assertInstanceOf(ReceiptTrip::class, $result->getRelatedTrips()[0]);

self::assertEmpty($result->getRelatedBalances());
self::assertInstanceOf(Token::class, $result->getToken());
$this->assertEmpty($result->getRelatedBalances());
$this->assertInstanceOf(Token::class, $result->getToken());
}

public function testGetReceiptNoAuth(): void
Expand Down
18 changes: 9 additions & 9 deletions tests/Functional/Api/TokensApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public function testGetCards(): void
$apiClient->Authenticate(new HeaderMethod('Authorization', 'Bearer TEST'));

$result = $apiClient->tokens()->getPaymentCards();
self::assertCount(1, $result);
self::assertIsString($result[0]->getExternalBackOfficeToken());
self::assertIsString($result[0]->getMediumType());
self::assertIsString($result[0]->getExternalTransitAccountToken());
self::assertIsString($result[0]->getStatus());
$this->assertCount(1, $result);
$this->assertIsString($result[0]->getExternalBackOfficeToken());
$this->assertIsString($result[0]->getMediumType());
$this->assertIsString($result[0]->getExternalTransitAccountToken());
$this->assertIsString($result[0]->getStatus());

$tokenPersonalization = $result[0]->getPersonalization();
self::assertInstanceOf(TokenPersonalization::class, $tokenPersonalization);
self::assertEquals('Pink', $tokenPersonalization->getColor());
self::assertEquals('PhysicalCard', $tokenPersonalization->getMedium());
self::assertEquals('', $tokenPersonalization->getName());
$this->assertInstanceOf(TokenPersonalization::class, $tokenPersonalization);
$this->assertSame('Pink', $tokenPersonalization->getColor());
$this->assertSame('PhysicalCard', $tokenPersonalization->getMedium());
$this->assertSame('', $tokenPersonalization->getName());
}

public function testGetCardsNoAuth(): void
Expand Down
Loading

0 comments on commit b9dccc0

Please sign in to comment.