Skip to content

Commit

Permalink
Check if consignment is found
Browse files Browse the repository at this point in the history
  • Loading branch information
Reindert Vetter committed Sep 23, 2019
1 parent 7b3c4a7 commit 64de874
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion Tests/SendConsignments/SendAgeCheckTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public function testSendOneConsignment()
return $this;
}


foreach ($this->additionProvider() as $consignmentTest) {


Expand Down
1 change: 1 addition & 0 deletions src/AutoLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_once ('Exception/AddressException.php');
require_once ('Exception/ApiException.php');
require_once ('Exception/MissingFieldException.php');
require_once ('Exception/NoConsignmentFoundException.php');
require_once ('Helper/RequestError.php');
require_once ('Helper/MyParcelCollection.php');
require_once ('Helper/MyParcelCurl.php');
Expand Down
7 changes: 7 additions & 0 deletions src/Exception/NoConsignmentFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace MyParcelNL\Sdk\src\Exception;

class NoConsignmentFoundException extends \Exception
{
}
11 changes: 10 additions & 1 deletion src/Helper/MyParcelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use MyParcelNL\Sdk\src\Adapter\ConsignmentAdapter;
use MyParcelNL\Sdk\src\Exception\ApiException;
use MyParcelNL\Sdk\src\Exception\MissingFieldException;
use MyParcelNL\Sdk\src\Exception\NoConsignmentFoundException;
use MyParcelNL\Sdk\src\Model\MyParcelConsignment;
use MyParcelNL\Sdk\src\Model\MyParcelRequest;
use MyParcelNL\Sdk\src\Services\CollectionEncode;
Expand Down Expand Up @@ -397,6 +398,10 @@ public function setLinkOfLabels($positions = self::DEFAULT_A4_POSITION)

$conceptIds = $this->getConsignmentIds($key);

if (null === $conceptIds) {
throw new NoConsignmentFoundException('No consignment found. The collection must contain at least one consignment.');
}

if ($key) {
$request = (new MyParcelRequest())
->setUserAgent($this->getUserAgent())
Expand Down Expand Up @@ -437,6 +442,10 @@ public function setPdfOfLabels($positions = self::DEFAULT_A4_POSITION)
->setLabelFormat($positions);
$conceptIds = $this->getConsignmentIds($key);

if (null === $conceptIds) {
throw new NoConsignmentFoundException('No consignment found. The collection must contain at least one consignment.');
}

if ($key) {
$request = (new MyParcelRequest())
->setUserAgent($this->getUserAgent())
Expand Down Expand Up @@ -629,7 +638,7 @@ public static function findMany(array $consignmentIds, string $apiKey): MyParcel
*/
public static function findByReferenceId(string $id, string $apiKey): MyParcelCollection
{
return self::findManyByReferenceId($id, $apiKey);
return self::findManyByReferenceId([$id], $apiKey);
}

/**
Expand Down

0 comments on commit 64de874

Please sign in to comment.