Skip to content

Commit

Permalink
Merge pull request #27 from vilkasgroup/fix_and_skip_some_tests
Browse files Browse the repository at this point in the history
Fix and skip some tests
  • Loading branch information
datqn7244 authored Sep 2, 2024
2 parents 45d704b + 5a6e441 commit 924c66e
Showing 1 changed file with 29 additions and 19 deletions.
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);
// }
}
}
}

0 comments on commit 924c66e

Please sign in to comment.