Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and skip some tests #27

Merged
merged 3 commits into from
Sep 2, 2024
Merged
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
48 changes: 29 additions & 19 deletions tests/PostnordClientTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @noinspection PhpUnitDeprecatedCallsIn10VersionInspection
* @noinspection PhpUnreachableStatementInspection
Expand Down Expand Up @@ -26,8 +27,8 @@ class PostnordClientTest extends TestCase
'shop_name' => 'Temp Dev',
'shop_party_id' => '1111111111',
'shop_street' => 'Finlaysoninkuja 19',
'shop_postcode' => '33210',
'shop_city' => 'Tampere',
'shop_postcode' => '00100',
'shop_city' => 'Helsinki',
'shop_country' => 'FI',
'shop_phone' => '+358123456789',
];
Expand All @@ -42,10 +43,10 @@ class PostnordClientTest extends TestCase
'servicePointId' => '9325',
'visitingAddress' => [
'countryCode' => 'FI',
'city' => 'TAMPERE',
'city' => 'HELSINKI',
'streetName' => 'Kuninkaankatu',
'streetNumber' => '14',
'postalCode' => '33210',
'postalCode' => '00100',
'additionalDescription' => null,
],
];
Expand Down Expand Up @@ -75,8 +76,8 @@ class PostnordClientTest extends TestCase
private $returnAddress = [
'return_name' => 'Temp Dev',
'return_street' => 'Finlaysoninkuja 19',
'return_postcode' => '33210',
'return_city' => 'Tampere',
'return_postcode' => '00100',
'return_city' => 'Helsinki',
'return_country' => 'FI',
];

Expand Down Expand Up @@ -111,6 +112,11 @@ class PostnordClientTest extends TestCase
'paperSize' => 'LABEL'
];

/**
* @var string Label id
*/
public $bookingId;

/**
* Skip everything if environment variables are not available and the client cannot be setup.
*/
Expand All @@ -134,8 +140,8 @@ public function testGetServicePointsByAddress(): void
$params = [
'countryCode' => 'FI',
'agreementCountry' => 'FI',
'city' => 'Tampere',
'postalCode' => '33210',
'city' => 'Helsinki',
'postalCode' => '00100',
'streetName' => 'Finlaysoninkuja',
'streetNumber' => '19',
'numberOfServicePoints' => 1,
Expand Down Expand Up @@ -235,6 +241,7 @@ public function testCreateBooking(): void
$this->assertArrayHasKey('bookingId', $results);
$this->assertArrayHasKey('value', $results['idInformation'][0]['ids'][0]);
$this->assertRegExp('/\d{20}/m', $results['idInformation'][0]['ids'][0]['value']);
$this->bookingId = $results['idInformation'][0]['ids'][0]['value'];
}

public function testCreateBookingWithPDF(): void
Expand All @@ -255,19 +262,20 @@ public function testCreateBookingWithPDF(): void

public function testGetPDFLabelFromId(): void
{
$this->markTestSkipped("Couldn't fetch labels. PostNord development server doesn't store booking information.");

$labelInfo = [
'paperSize' => 'LABEL',
];
$labelId = '00364300432996651506';
$results = $this->client->getPDFLabelFromId($labelId, $labelInfo);
$results = $this->client->getPDFLabelFromId($this->bookingId, $labelInfo);
$this->assertArrayHasKey('printout', $results[0]);
}


public function testGetReturnPDFLabelFromId(): void
{
$itemId = '00364300432996662601';
$results = $this->client->getReturnPDFLabelFromId($itemId, $this->labelInfo);
$this->markTestSkipped("Couldn't fetch labels. PostNord development server doesn't store booking information.");

$results = $this->client->getReturnPDFLabelFromId($this->bookingId, $this->labelInfo);
$this->assertArrayHasKey('bookingResponse', $results);
}

Expand Down Expand Up @@ -303,12 +311,14 @@ public function testCreateBookingAndGetBothLabel(): void
// Postnord use the same id for item and label
if (!empty($labelIds)) {
$this->assertEquals(2, count($labelIds), 'Not enough label ids');
foreach ($labelIds as $itemId) {
$results = $this->client->getPDFLabelFromId($itemId, $this->labelInfo);
$this->assertArrayHasKey('printout', $results[0]);
$results = $this->client->getReturnPDFLabelFromId($itemId, $this->labelInfo);
$this->assertArrayHasKey('bookingResponse', $results);
}

// Couldn't fetch labels from PostNord development server
// foreach ($labelIds as $itemId) {
// $results = $this->client->getPDFLabelFromId($itemId, $labelInfo);
// $this->assertArrayHasKey('printout', $results[0]);
// $results = $this->client->getReturnPDFLabelFromId($itemId, $labelInfo);
// $this->assertArrayHasKey('bookingResponse', $results);
// }
}
}
}