From 117c46430adcffd1ece067dfd8b818363a3413a2 Mon Sep 17 00:00:00 2001 From: radua Date: Sun, 23 Mar 2025 17:58:44 -0400 Subject: [PATCH 1/2] Fix compatibility issues with PHP 8.1 and above --- Apis/Exceptions/ApiException.php | 8 +++++-- Apis/Requests/ApiRequest.php | 4 ++++ .../AvailableServicesCollection.php | 6 ++--- Shipping/Objects/Address.php | 4 ++-- Shipping/Objects/Manifest.php | 4 ++-- Shipping/Objects/Package.php | 4 ++-- Shipping/Objects/Packing.php | 4 ++-- Shipping/Objects/Pickup.php | 5 ++-- Shipping/Objects/Rate.php | 3 +-- Shipping/Objects/Service.php | 3 +-- Shipping/Objects/Shipment.php | 4 ++-- Shipping/Objects/TrackShipment.php | 4 ++-- .../Requests/AssociateShipmentRequest.php | 17 ++++++++----- Shipping/Requests/AssociateToDepotRequest.php | 16 +++++++++---- .../Requests/AvailableServicesRequest.php | 18 ++++++++------ .../Requests/CancelManifestByIdRequest.php | 14 +++++++---- Shipping/Requests/CancelPickupRequest.php | 19 ++++++++++----- Shipping/Requests/CancelShipmentRequest.php | 18 +++++++++----- .../Requests/ConfirmManifestByIdRequest.php | 15 ++++++++---- .../Requests/ConfirmShipmentByIdRequest.php | 24 ++++++++++++------- Shipping/Requests/ConfirmShipmentRequest.php | 19 +++++++++------ Shipping/Requests/CreateManifestRequest.php | 16 ++++++++----- Shipping/Requests/CreatePickupRequest.php | 20 +++++++++------- Shipping/Requests/EditPickupRequest.php | 21 +++++++++------- Shipping/Requests/EditShipmentRequest.php | 18 ++++++++------ .../Requests/GetAddressByTokenRequest.php | 16 +++++++++---- .../GetDhlEcommOpenShipmentsRequest.php | 12 ++++++---- Shipping/Requests/GetDhlEcommRatesRequest.php | 19 +++++++++------ Shipping/Requests/GetManifestByIdRequest.php | 14 +++++++---- Shipping/Requests/GetManifestsListRequest.php | 13 ++++++---- Shipping/Requests/GetPickupListRequest.php | 14 +++++++---- Shipping/Requests/GetShipmentByIdRequest.php | 17 ++++++++----- Shipping/Requests/GetShipmentListRequest.php | 16 ++++++++----- Shipping/Requests/PackingRequest.php | 18 ++++++++------ Shipping/Requests/PrepareShipmentRequest.php | 19 ++++++++------- Shipping/Requests/QuoteRequest.php | 19 ++++++++------- Shipping/Requests/TrackShipmentRequest.php | 18 +++++++++----- Shipping/Requests/ValidateTokenRequest.php | 16 ++++++++----- Shipping/Tests/AssociateShipmentTests.php | 2 +- Shipping/Tests/AssociateToDepotTests.php | 2 +- .../AvailableServicesCollectionTests.php | 1 + Shipping/Tests/AvailableServicesTests.php | 5 +++- Shipping/Tests/CancelManifestByIdTests.php | 4 +++- Shipping/Tests/ConfirmManifestByIdTests.php | 6 ++++- Shipping/Tests/ConfirmShipmentTests.php | 4 +++- Shipping/Tests/CreateManifestTests.php | 6 ++++- Shipping/Tests/CreatePickupTests.php | 6 ++++- Shipping/Tests/EditPickupTests.php | 6 +++-- Shipping/Tests/EditShipmentTests.php | 4 +++- .../Tests/GetDhlEcommOpenShipmentsTests.php | 10 +++++--- Shipping/Tests/GetDhlEcommRatesTests.php | 6 ++++- Shipping/Tests/GetManifestByIdTests.php | 6 ++++- Shipping/Tests/GetManifestsListTests.php | 6 ++++- Shipping/Tests/GetPickupListTests.php | 5 +++- .../Tests/GetPickupListsCollectionTests.php | 3 ++- Shipping/Tests/GetShipmentByIdTests.php | 12 ++++++---- Shipping/Tests/GetShipmentListTests.php | 6 ++++- .../Tests/GetShipmentListsCollectionTests.php | 2 ++ Shipping/Tests/ManifestTests.php | 4 +++- Shipping/Tests/PackingTests.php | 4 +++- Shipping/Tests/PickupTests.php | 3 ++- Shipping/Tests/PrepareShipmentTests.php | 4 +++- Shipping/Tests/QuoteTests.php | 6 ++++- Shipping/Tests/RateTests.php | 4 +++- Shipping/Tests/RatesCollectionTests.php | 2 ++ Shipping/Tests/ShipmentTests.php | 4 +++- Shipping/Tests/TrackShipmentTests.php | 4 +++- Shipping/Tests/ValidateTokenTests.php | 8 +++---- composer.json | 4 ++-- phpunit.xml.dist | 23 +++++++++--------- 70 files changed, 437 insertions(+), 234 deletions(-) diff --git a/Apis/Exceptions/ApiException.php b/Apis/Exceptions/ApiException.php index 2e60614..a97f490 100644 --- a/Apis/Exceptions/ApiException.php +++ b/Apis/Exceptions/ApiException.php @@ -2,8 +2,12 @@ namespace Flagship\Apis\Exceptions; -class ApiException extends \Exception{ - public function __construct(string $message, int $code=0){ +class ApiException extends \Exception +{ + + public function __construct(string $message, int $code=0) + { parent::__construct($message,$code); } + } diff --git a/Apis/Requests/ApiRequest.php b/Apis/Requests/ApiRequest.php index e7aab49..a9d0d9c 100644 --- a/Apis/Requests/ApiRequest.php +++ b/Apis/Requests/ApiRequest.php @@ -6,6 +6,10 @@ abstract class ApiRequest{ + protected $headers = []; + protected $filters = []; + protected $url; + public function setStoreName(string $storeName){ $this->setHeader("X-Store-Name",$storeName); return $this; diff --git a/Shipping/Collections/AvailableServicesCollection.php b/Shipping/Collections/AvailableServicesCollection.php index 8c9c0fb..335a7d3 100644 --- a/Shipping/Collections/AvailableServicesCollection.php +++ b/Shipping/Collections/AvailableServicesCollection.php @@ -36,7 +36,7 @@ public function getStandardServices() : AvailableServicesCollection { }); if($services->isEmpty()){ - throw new AvailableServicesException('No services for courier - '.$courier); + throw new AvailableServicesException('No standard services available'); } return $services; @@ -48,7 +48,7 @@ public function getOvernightServices() : AvailableServicesCollection { }); if($services->isEmpty()){ - throw new AvailableServicesException('No services for courier - '.$courier); + throw new AvailableServicesException('No overnight services available'); } return $services; @@ -60,7 +60,7 @@ public function getExpressServices() : AvailableServicesCollection { }); if($services->isEmpty()){ - throw new AvailableServicesException('No services for courier - '.$courier); + throw new AvailableServicesException('No express services available'); } return $services; diff --git a/Shipping/Objects/Address.php b/Shipping/Objects/Address.php index 2be6d01..4d78b90 100755 --- a/Shipping/Objects/Address.php +++ b/Shipping/Objects/Address.php @@ -2,8 +2,8 @@ namespace Flagship\Shipping\Objects; class Address{ - public function __construct(\stdClass $address){ - $this->address = $address; + public function __construct(public \stdClass $address) + { } public function getId() : int { diff --git a/Shipping/Objects/Manifest.php b/Shipping/Objects/Manifest.php index cc67c39..67fd190 100644 --- a/Shipping/Objects/Manifest.php +++ b/Shipping/Objects/Manifest.php @@ -8,8 +8,8 @@ class Manifest{ - public function __construct(\stdClass $manifest){ - $this->manifest = $manifest; + public function __construct(public \stdClass $manifest) + { } public function getName() : string { diff --git a/Shipping/Objects/Package.php b/Shipping/Objects/Package.php index 60c5a70..5873264 100644 --- a/Shipping/Objects/Package.php +++ b/Shipping/Objects/Package.php @@ -3,7 +3,7 @@ namespace Flagship\Shipping\Objects; class Package{ - public function __construct(array $package){ - $this->package = $package; + public function __construct(public array $package) + { } } diff --git a/Shipping/Objects/Packing.php b/Shipping/Objects/Packing.php index ef22047..140efa7 100644 --- a/Shipping/Objects/Packing.php +++ b/Shipping/Objects/Packing.php @@ -3,8 +3,8 @@ namespace Flagship\Shipping\Objects; class Packing{ - public function __construct(\stdClass $packing){ - $this->packing = $packing; + public function __construct(public \stdClass $packing) + { } public function getBoxModel() : string { diff --git a/Shipping/Objects/Pickup.php b/Shipping/Objects/Pickup.php index ee161be..67862c8 100644 --- a/Shipping/Objects/Pickup.php +++ b/Shipping/Objects/Pickup.php @@ -3,8 +3,9 @@ class Pickup{ - public function __construct(\stdClass $pickup){ - $this->pickup = $pickup; + public function __construct( + public \stdClass $pickup) + { } public function getId() : int { diff --git a/Shipping/Objects/Rate.php b/Shipping/Objects/Rate.php index c8c2360..8c260cb 100644 --- a/Shipping/Objects/Rate.php +++ b/Shipping/Objects/Rate.php @@ -4,9 +4,8 @@ class Rate { - public function __construct( \stdClass $rate ) + public function __construct(public \stdClass $rate ) { - $this->rate = $rate; } public function getTotal() : float diff --git a/Shipping/Objects/Service.php b/Shipping/Objects/Service.php index 87d0492..e14e5f1 100644 --- a/Shipping/Objects/Service.php +++ b/Shipping/Objects/Service.php @@ -4,9 +4,8 @@ class Service { - public function __construct( \stdClass $service ) + public function __construct( public \stdClass $service ) { - $this->service = $service; } public function getCode() : string { diff --git a/Shipping/Objects/Shipment.php b/Shipping/Objects/Shipment.php index 53f6e1e..988ee9e 100644 --- a/Shipping/Objects/Shipment.php +++ b/Shipping/Objects/Shipment.php @@ -7,8 +7,8 @@ class Shipment{ - public function __construct(\stdclass $shipment){ - $this->shipment = $shipment; + public function __construct(public \stdclass $shipment) + { } public function getId() : int { diff --git a/Shipping/Objects/TrackShipment.php b/Shipping/Objects/TrackShipment.php index 0cc1dbe..b69297a 100644 --- a/Shipping/Objects/TrackShipment.php +++ b/Shipping/Objects/TrackShipment.php @@ -4,8 +4,8 @@ class TrackShipment { - public function __construct(?\stdClass $trackShipment){ - $this->trackShipment = $trackShipment; + public function __construct(public ?\stdClass $trackShipment) + { } public function getCurrentStatus() : string { diff --git a/Shipping/Requests/AssociateShipmentRequest.php b/Shipping/Requests/AssociateShipmentRequest.php index d960e7e..7c1e4f4 100644 --- a/Shipping/Requests/AssociateShipmentRequest.php +++ b/Shipping/Requests/AssociateShipmentRequest.php @@ -3,16 +3,21 @@ namespace Flagship\Shipping\Requests; use Flagship\Apis\Requests\ApiRequest; use Flagship\Shipping\Exceptions\AssociateShipmentException; -use Flagship\Apis\Exception\ApiException; +use Flagship\Apis\Exceptions\ApiException; class AssociateShipmentRequest extends ApiRequest{ - public function __construct(string $apiToken, string $baseUrl, int $manifestId, array $payload,string $flagshipFor, string $version){ + protected $responseCode; + protected $apiUrl; - $this->apiToken = $apiToken; + public function __construct( + protected string $apiToken, + string $baseUrl, + int $manifestId, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ $this->apiUrl = $baseUrl.'/ship/edhl/associate/'.$manifestId; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : bool { diff --git a/Shipping/Requests/AssociateToDepotRequest.php b/Shipping/Requests/AssociateToDepotRequest.php index 341c01e..29e0b1e 100644 --- a/Shipping/Requests/AssociateToDepotRequest.php +++ b/Shipping/Requests/AssociateToDepotRequest.php @@ -8,12 +8,18 @@ class AssociateToDepotRequest extends ApiRequest{ - public function __construct(string $apiToken,string $baseUrl,int $manifestId,array $payload,string $flagshipFor,string $version){ - $this->apiToken = $apiToken; + protected $apiUrl; + protected $responseCode; + + public function __construct( + protected string $apiToken, + string $baseUrl, + int $manifestId, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ $this->apiUrl = $baseUrl.'/ship/edhl/to-depot/'.$manifestId; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : bool { diff --git a/Shipping/Requests/AvailableServicesRequest.php b/Shipping/Requests/AvailableServicesRequest.php index 9a65e3d..29813f0 100644 --- a/Shipping/Requests/AvailableServicesRequest.php +++ b/Shipping/Requests/AvailableServicesRequest.php @@ -6,18 +6,22 @@ use Flagship\Shipping\Collections\AvailableServicesCollection; class AvailableServicesRequest extends ApiRequest{ + protected $responseCode; - - public function __construct(string $token,string $baseUrl,string $flagshipFor,string $version){ - $this->token = $token; - $this->url = $baseUrl.'/ship/available_services'; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $apiToken, + string $baseUrl, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/available_services'; } public function execute() : AvailableServicesCollection { try{ - $response = $this->api_request($this->url,[],$this->token,'GET',10,$this->flagshipFor,$this->version); + $response = $this->api_request($this->apiUrl,[],$this->apiToken,'GET',10,$this->flagshipFor,$this->version); $availableServicesArray = $this->createArrayOfServices($response); $availableServicesCollection = new AvailableServicesCollection(); $availableServicesCollection->importServices($availableServicesArray); diff --git a/Shipping/Requests/CancelManifestByIdRequest.php b/Shipping/Requests/CancelManifestByIdRequest.php index 7fe9328..48945f6 100644 --- a/Shipping/Requests/CancelManifestByIdRequest.php +++ b/Shipping/Requests/CancelManifestByIdRequest.php @@ -6,12 +6,18 @@ use Flagship\Shipping\Exceptions\CancelManifestByIdException; class CancelManifestByIdRequest extends ApiRequest{ + + protected $apiUrl; + protected $responseCode; - public function __construct(string $apiToken,string $baseUrl,int $manifestId,string $flagshipFor,string $version){ - $this->apiToken = $apiToken; + public function __construct( + protected string $apiToken, + protected string $baseUrl, + int $manifestId, + protected string $flagshipFor, + protected string $version + ){ $this->apiUrl = $baseUrl.'/ship/edhl/'.$manifestId; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : bool { diff --git a/Shipping/Requests/CancelPickupRequest.php b/Shipping/Requests/CancelPickupRequest.php index 73efa12..db39490 100644 --- a/Shipping/Requests/CancelPickupRequest.php +++ b/Shipping/Requests/CancelPickupRequest.php @@ -5,16 +5,23 @@ use Flagship\Shipping\Exceptions\CancelPickupException; class CancelPickupRequest extends ApiRequest{ - public function __construct(string $baseUrl,string $token,int $id, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/pickups/'.$id; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + + protected $apiUrl; + protected $responseCode; + + public function __construct( + string $baseUrl, + protected string $apiToken, + int $id, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/pickups/'.$id; } public function execute() : bool { try{ - $cancelPickupRequest = $this->api_request($this->url,[],$this->token,'DELETE',30,$this->flagshipFor,$this->version); + $cancelPickupRequest = $this->api_request($this->apiUrl,[],$this->apiToken,'DELETE',30,$this->flagshipFor,$this->version); $this->responseCode = $cancelPickupRequest["httpcode"]; return $cancelPickupRequest["httpcode"] == 200 ? TRUE : FALSE; } diff --git a/Shipping/Requests/CancelShipmentRequest.php b/Shipping/Requests/CancelShipmentRequest.php index 8cdda32..8273f2e 100644 --- a/Shipping/Requests/CancelShipmentRequest.php +++ b/Shipping/Requests/CancelShipmentRequest.php @@ -5,17 +5,23 @@ use Flagship\Shipping\Exceptions\CancelShipmentException; class CancelShipmentRequest extends ApiRequest{ - public function __construct(string $baseUrl,string $token, int $id, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/ship/shipments/'.$id; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + protected $responseCode; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + int $id, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/shipments/'.$id; } public function execute() : bool { try{ - $cancelShipmentRequest = $this->api_request($this->url,[],$this->token,'DELETE',0,$this->flagshipFor,$this->version); + $cancelShipmentRequest = $this->api_request($this->apiUrl,[],$this->apiToken,'DELETE',0,$this->flagshipFor,$this->version); $this->responseCode = $cancelShipmentRequest["httpcode"]; return $cancelShipmentRequest["httpcode"] ==200 ? TRUE : FALSE; } diff --git a/Shipping/Requests/ConfirmManifestByIdRequest.php b/Shipping/Requests/ConfirmManifestByIdRequest.php index 1a0e3a7..308a697 100644 --- a/Shipping/Requests/ConfirmManifestByIdRequest.php +++ b/Shipping/Requests/ConfirmManifestByIdRequest.php @@ -8,11 +8,18 @@ class ConfirmManifestByIdRequest extends ApiRequest{ - public function __construct(string $token,string $baseUrl,int $manifestId,string $flagshipFor,string $version){ - $this->apiToken = $token; + protected $apiUrl; + protected $responseCode; + + public function __construct( + protected string $apiToken, + string $baseUrl, + int $manifestId, + protected string $flagshipFor, + protected string $version + ){ $this->apiUrl = $baseUrl.'/ship/edhl/close/'.$manifestId; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + } public function execute() : Manifest { diff --git a/Shipping/Requests/ConfirmShipmentByIdRequest.php b/Shipping/Requests/ConfirmShipmentByIdRequest.php index ebaea9c..9f47523 100755 --- a/Shipping/Requests/ConfirmShipmentByIdRequest.php +++ b/Shipping/Requests/ConfirmShipmentByIdRequest.php @@ -7,20 +7,26 @@ use Flagship\Shipping\Exceptions\ConfirmShipmentByIdException; class ConfirmShipmentByIdRequest extends ApiRequest{ + protected $responseCode; - public function __construct(string $baseUrl, string $token, int $id, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/ship/'.$id.'/confirm'; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + int $id, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/'.$id.'/confirm'; } public function execute() : Shipment { try{ - $confirmShipmentRequest = $this->api_request($this->url,[],$this->token,'PUT',30,$this->flagshipFor,$this->version); - - $confirmShipmentObject = count((array)$confirmShipmentRequest["response"]) == 0 ? new \stdClass() : $confirmShipmentRequest["response"]->content; - + $confirmShipmentRequest = $this->api_request + ($this->apiUrl,[],$this->apiToken,'PUT',30,$this->flagshipFor,$this->version); + $confirmShipmentObject = count((array)$confirmShipmentRequest["response"]) == 0 + ? new \stdClass() : $confirmShipmentRequest["response"]->content; $confirmShipment = new Shipment($confirmShipmentObject); $this->responseCode = $confirmShipmentRequest["httpcode"]; return $confirmShipment; diff --git a/Shipping/Requests/ConfirmShipmentRequest.php b/Shipping/Requests/ConfirmShipmentRequest.php index 9728b18..d4b4b94 100644 --- a/Shipping/Requests/ConfirmShipmentRequest.php +++ b/Shipping/Requests/ConfirmShipmentRequest.php @@ -8,18 +8,23 @@ use Flagship\Shipping\Exceptions\ConfirmShipmentException; class ConfirmShipmentRequest extends ApiRequest{ + protected $responseCode; - public function __construct(string $baseUrl, string $token, array $payload, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/ship/confirm'; - $this->token = $token; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + string $baseUrl, + protected string $apiToken, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/confirm'; } public function execute() : Shipment { try{ - $confirmShipmentRequest = $this->api_request($this->url,$this->payload,$this->token,'POST',30,$this->flagshipFor,$this->version); + $confirmShipmentRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',30,$this->flagshipFor,$this->version); $confirmShipmentObject = count((array)$confirmShipmentRequest["response"]) == 0 ? new \stdClass() : $confirmShipmentRequest["response"]->content; diff --git a/Shipping/Requests/CreateManifestRequest.php b/Shipping/Requests/CreateManifestRequest.php index bd6783c..89ec88f 100644 --- a/Shipping/Requests/CreateManifestRequest.php +++ b/Shipping/Requests/CreateManifestRequest.php @@ -7,14 +7,18 @@ use Flagship\Shipping\Exceptions\CreateManifestException; use Flagship\Shipping\Objects\Manifest; -class CreateManifestRequest extends ApiRequest{ +class CreateManifestRequest extends ApiRequest +{ + protected $responseCode; - public function __construct(string $token,string $baseUrl,array $payload,string $flagshipFor,string $version){ - $this->apiToken = $token; + public function __construct( + protected string $apiToken, + protected string $baseUrl, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ $this->baseUrl = $baseUrl.'/ship/edhl/create'; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : Manifest { diff --git a/Shipping/Requests/CreatePickupRequest.php b/Shipping/Requests/CreatePickupRequest.php index b757504..2709afa 100644 --- a/Shipping/Requests/CreatePickupRequest.php +++ b/Shipping/Requests/CreatePickupRequest.php @@ -7,20 +7,24 @@ use Flagship\Apis\Exceptions\ApiException; use Flagship\Shipping\Exceptions\CreatePickupException; - class CreatePickupRequest extends ApiRequest{ + protected $responseCode; - public function __construct(string $baseUrl,string $token,array $pickupPayload, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/pickups'; - $this->token = $token; - $this->pickupPayload = $pickupPayload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/pickups'; } public function execute() : Pickup { try{ - $pickupRequest = $this->api_request($this->url,$this->pickupPayload,$this->token,'POST',30,$this->flagshipFor,$this->version); + $pickupRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',30,$this->flagshipFor,$this->version); $pickupObject = count((array)$pickupRequest["response"]) == 0 ? new \stdClass() : ( is_array($pickupRequest["response"]->content) ? diff --git a/Shipping/Requests/EditPickupRequest.php b/Shipping/Requests/EditPickupRequest.php index 75c7006..318d0e7 100644 --- a/Shipping/Requests/EditPickupRequest.php +++ b/Shipping/Requests/EditPickupRequest.php @@ -9,19 +9,22 @@ class EditPickupRequest extends ApiRequest{ protected $responseCode; - - public function __construct(string $baseUrl,string $token,array $payload,string $id, string $flagshipFor, string $version){ - - $this->url = $baseUrl.'/pickups/'.$id; - $this->token = $token; - $this->editPickupPayload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected array $payload, + protected string $id, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/pickups/'.$id; } public function execute() : Pickup { try{ - $editPickupRequest = $this->api_request($this->url,$this->editPickupPayload,$this->token,'PUT',30,$this->flagshipFor,$this->version); + $editPickupRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'PUT',30,$this->flagshipFor,$this->version); $pickupObject = count((array)$editPickupRequest["response"]) == 0 ? new \stdClass() : $editPickupRequest["response"]->content; $editPickup = new Pickup($pickupObject); $this->responseCode = $editPickupRequest["httpcode"]; diff --git a/Shipping/Requests/EditShipmentRequest.php b/Shipping/Requests/EditShipmentRequest.php index cff345b..ca2e3b0 100644 --- a/Shipping/Requests/EditShipmentRequest.php +++ b/Shipping/Requests/EditShipmentRequest.php @@ -9,18 +9,22 @@ class EditShipmentRequest extends Apirequest{ protected $responseCode; + protected $apiUrl; - public function __construct(string $baseUrl,string $token,array $payload,string $shipmentId, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/ship/shipments/'.$shipmentId; - $this->token = $token; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected array $payload, + string $shipmentId, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/shipments/'.$shipmentId; } public function execute() : Shipment { try{ - $editShipmentRequest = $this->api_request($this->url,$this->payload,$this->token,'PUT',30,$this->flagshipFor,$this->version); + $editShipmentRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'PUT',30,$this->flagshipFor,$this->version); $editShipmentObject = count((array)$editShipmentRequest["response"]) == 0 ? new \stdClass() : $editShipmentRequest["response"]->content; $editShipment = new Shipment($editShipmentObject); $this->responseCode = $editShipmentRequest["httpcode"]; diff --git a/Shipping/Requests/GetAddressByTokenRequest.php b/Shipping/Requests/GetAddressByTokenRequest.php index 2297455..4195345 100755 --- a/Shipping/Requests/GetAddressByTokenRequest.php +++ b/Shipping/Requests/GetAddressByTokenRequest.php @@ -7,16 +7,22 @@ use Flagship\Shipping\Exceptions\GetAddressByTokenException; class GetAddressByTokenRequest extends ApiRequest{ - public function __construct(string $apiToken,string $baseUrl,string $flagshipFor,string $version){ + + protected int $responseCode; + protected string $url; + + public function __construct( + protected string $apiToken, + string $baseUrl, + protected string $flagshipFor, + protected string $version) + { $this->url = $baseUrl.'/addresses?is_hq=1'; - $this->token = $apiToken; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute(){ try{ - $getAddressRequest = $this->api_request($this->url,[],$this->token,'GET',10,$this->flagshipFor,$this->version); + $getAddressRequest = $this->api_request($this->url,[],$this->apiToken,'GET',10,$this->flagshipFor,$this->version); $addressObject = count((array)$getAddressRequest["response"]) == 0 ? [] : $getAddressRequest["response"]->content->records; $address = new Address(reset($addressObject)); $this->responseCode = $getAddressRequest['httpcode']; diff --git a/Shipping/Requests/GetDhlEcommOpenShipmentsRequest.php b/Shipping/Requests/GetDhlEcommOpenShipmentsRequest.php index 8252b2e..8a4573c 100644 --- a/Shipping/Requests/GetDhlEcommOpenShipmentsRequest.php +++ b/Shipping/Requests/GetDhlEcommOpenShipmentsRequest.php @@ -8,11 +8,15 @@ class GetDhlEcommOpenShipmentsRequest extends ApiRequest{ - public function __construct(string $token,string $baseUrl,string $flagshipFor,string $version){ - $this->apiToken = $token; + protected int $responseCode; + protected string $apiUrl; + public function __construct( + protected string $apiToken, + string $baseUrl, + protected string $flagshipFor, + protected string $version) + { $this->apiUrl = $baseUrl.'/ship/edhl/open-shipments'; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : GetShipmentListCollection { diff --git a/Shipping/Requests/GetDhlEcommRatesRequest.php b/Shipping/Requests/GetDhlEcommRatesRequest.php index f1ecf3c..6b5624b 100644 --- a/Shipping/Requests/GetDhlEcommRatesRequest.php +++ b/Shipping/Requests/GetDhlEcommRatesRequest.php @@ -9,17 +9,22 @@ class GetDhlEcommRatesRequest extends ApiRequest{ - public function __construct(string $token,string $baseUrl,array $payload,string $flagshipFor,string $version){ - $this->token = $token; - $this->url = $baseUrl.'/ship/edhl/rates'; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected int $responseCode; + protected string $apiUrl; + + public function __construct( + protected string $apiToken, + string $baseUrl, + protected array $payload, + protected string $flagshipFor, + protected string $version) + { + $this->apiUrl = $baseUrl.'/ship/edhl/rates'; } public function execute() : RatesCollection { try{ - $responseArray = $this->api_request($this->url,$this->payload,$this->token,'POST',30,$this->flagshipFor,$this->version); + $responseArray = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',30,$this->flagshipFor,$this->version); $responseObject = count((array)$responseArray["response"]) == 0 ? [] : $responseArray["response"]->content; $rates = new RatesCollection(); $rates->importRates($responseObject); diff --git a/Shipping/Requests/GetManifestByIdRequest.php b/Shipping/Requests/GetManifestByIdRequest.php index f6c4ebc..e493439 100644 --- a/Shipping/Requests/GetManifestByIdRequest.php +++ b/Shipping/Requests/GetManifestByIdRequest.php @@ -8,11 +8,17 @@ class GetManifestByIdRequest extends ApiRequest { - public function __construct(string $token, string $baseUrl, int $manifestId, string $flagshipFor, string $version){ - $this->apiToken = $token; + protected int $responseCode; + protected string $apiUrl; + + public function __construct( + protected string $apiToken, + protected string $baseUrl, + int $manifestId, + protected string $flagshipFor, + protected string $version) + { $this->apiUrl = $baseUrl.'/ship/edhl/'.$manifestId; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : Manifest { diff --git a/Shipping/Requests/GetManifestsListRequest.php b/Shipping/Requests/GetManifestsListRequest.php index c8dfb27..37ef7e5 100644 --- a/Shipping/Requests/GetManifestsListRequest.php +++ b/Shipping/Requests/GetManifestsListRequest.php @@ -9,11 +9,16 @@ class GetManifestsListRequest extends ApiRequest{ - public function __construct(string $token, string $baseUrl,string $flagshipFor,string $version){ - $this->apiToken = $token; + protected int $responseCode; + protected string $apiUrl; + + public function __construct( + protected string $apiToken, + string $baseUrl, + protected string $flagshipFor, + protected string $version) + { $this->apiUrl = $baseUrl.'/ship/edhl/'; - $this->flagshipFor = $flagshipFor; - $this->version = $version; } public function execute() : ManifestListCollection { diff --git a/Shipping/Requests/GetPickupListRequest.php b/Shipping/Requests/GetPickupListRequest.php index 04e5d08..696566d 100644 --- a/Shipping/Requests/GetPickupListRequest.php +++ b/Shipping/Requests/GetPickupListRequest.php @@ -11,11 +11,15 @@ class GetPickupListRequest extends ApiRequest{ protected $responseCode; protected $filters; - public function __construct(string $baseUrl,string $token, string $flagshipFor, string $version){ + protected $url; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected string $flagshipFor, + protected string $version) + { $this->url = $baseUrl.'/pickups'; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; $this->filters =[ 'courier', 'date', @@ -26,7 +30,7 @@ public function __construct(string $baseUrl,string $token, string $flagshipFor, public function execute() : GetPickupListCollection { try{ - $getPickupListRequest = $this->api_request($this->url,[],$this->token,'GET',10,$this->flagshipFor,$this->version); + $getPickupListRequest = $this->api_request($this->url,[],$this->apiToken,'GET',10,$this->flagshipFor,$this->version); $getPickupListRecords = count((array)$getPickupListRequest["response"]) == 0 ? [] : $getPickupListRequest["response"]->content->records; $pickupList = new GetPickupListCollection(); $pickupList->importPickups($getPickupListRecords); diff --git a/Shipping/Requests/GetShipmentByIdRequest.php b/Shipping/Requests/GetShipmentByIdRequest.php index 76ffca3..e33d272 100644 --- a/Shipping/Requests/GetShipmentByIdRequest.php +++ b/Shipping/Requests/GetShipmentByIdRequest.php @@ -10,16 +10,21 @@ class GetShipmentByIdRequest extends ApiRequest{ protected $responseCode; - public function __construct(string $baseUrl,string $token,string $flagshipFor,string $version,int $id){ - $this->url = $baseUrl.'/ship/shipments/'.$id; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + string $baseUrl, + protected string $apiToken, + protected string $flagshipFor, + protected string $version, + int $id) + { + $this->apiUrl = $baseUrl.'/ship/shipments/'.$id; } public function execute() : Shipment { try{ - $response = $this->api_request($this->url,[],$this->token,"GET",10,$this->flagshipFor,$this->version); + $response = $this->api_request($this->apiUrl,[],$this->apiToken,"GET",10,$this->flagshipFor,$this->version); $responseObject = count((array)$response["response"]) == 0 ? new \stdClass() : $response["response"]->content; $shipment = new Shipment($responseObject); $this->responseCode = $response["httpcode"]; diff --git a/Shipping/Requests/GetShipmentListRequest.php b/Shipping/Requests/GetShipmentListRequest.php index 112fc50..a5e19b1 100644 --- a/Shipping/Requests/GetShipmentListRequest.php +++ b/Shipping/Requests/GetShipmentListRequest.php @@ -12,11 +12,15 @@ class GetShipmentListRequest extends ApiRequest{ protected $responseCode; protected $filters; - public function __construct(string $baseUrl,string $token, string $flagshipFor, string $version) { - $this->token = $token; - $this->url = $baseUrl . '/ship/shipments'; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected string $flagshipFor, + protected string $version) + { + $this->apiUrl = $baseUrl . '/ship/shipments'; $this->filters = [ 'courier', 'status', @@ -30,7 +34,7 @@ public function __construct(string $baseUrl,string $token, string $flagshipFor, public function execute() : GetShipmentListCollection { try{ - $request = $this->api_request($this->url,[],$this->token,"GET",30,$this->flagshipFor,$this->version); + $request = $this->api_request($this->apiUrl,[],$this->apiToken,"GET",30,$this->flagshipFor,$this->version); $shipmentRecords = count((array)$request["response"]) == 0 ? [] : $request["response"]->content->records; $shipments = new GetShipmentListCollection(); $shipments->importShipments($shipmentRecords); diff --git a/Shipping/Requests/PackingRequest.php b/Shipping/Requests/PackingRequest.php index 6da9cb6..0c5575f 100644 --- a/Shipping/Requests/PackingRequest.php +++ b/Shipping/Requests/PackingRequest.php @@ -9,17 +9,21 @@ class PackingRequest extends ApiRequest{ protected $responseCode; - public function __construct(string $baseUrl,string $token, array $payload, string $flagshipFor, string $version){ - $this->token = $token; - $this->url = $baseUrl.'/v2/ship/packing'; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected array $payload, + protected string $flagshipFor, + protected string $version) + { + $this->apiUrl = $baseUrl.'/v2/ship/packing'; } public function execute() : PackingCollection { try{ - $packingRequest = $this->api_request($this->url,$this->payload,$this->token,'POST',30,$this->flagshipFor,$this->version); + $packingRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',30,$this->flagshipFor,$this->version); $packagingObject = count((array)$packingRequest["response"]) == 0 ? [] : $packingRequest["response"]->content->packages; $packages = new PackingCollection(); diff --git a/Shipping/Requests/PrepareShipmentRequest.php b/Shipping/Requests/PrepareShipmentRequest.php index 8026bc5..5747dc9 100644 --- a/Shipping/Requests/PrepareShipmentRequest.php +++ b/Shipping/Requests/PrepareShipmentRequest.php @@ -7,20 +7,23 @@ use Flagship\Shipping\Exceptions\PrepareShipmentException; class PrepareShipmentRequest extends ApiRequest{ - protected $responseCode; - public function __construct(string $baseUrl, string $token, array $payload, string $flagshipFor, string $version){ + protected $responseCode; + protected $apiUrl; - $this->url = $baseUrl.'/ship/prepare'; - $this->token = $token; - $this->payload = $payload; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/ship/prepare'; } public function execute() : ?Shipment { try{ - $prepareShipmentRequest = $this->api_request($this->url,$this->payload,$this->token,'POST',30,$this->flagshipFor,$this->version); + $prepareShipmentRequest = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',30,$this->flagshipFor,$this->version); $responseObject = count((array)$prepareShipmentRequest["response"]) == 0 ? new \stdClass() : $prepareShipmentRequest["response"]->content ; $prepareShipment = new Shipment($responseObject); $this->responseCode = $prepareShipmentRequest["httpcode"]; diff --git a/Shipping/Requests/QuoteRequest.php b/Shipping/Requests/QuoteRequest.php index 6e99629..8ebcd63 100644 --- a/Shipping/Requests/QuoteRequest.php +++ b/Shipping/Requests/QuoteRequest.php @@ -10,19 +10,22 @@ class QuoteRequest extends ApiRequest{ protected $responseCode; - - public function __construct(string $token,string $baseUrl,array $payloadArray, string $flagshipFor, string $version){ - $this->token = $token; - $this->payload = $payloadArray; - $this->url = $baseUrl . '/ship/rates'; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected $apiUrl; + + public function __construct( + protected string $apiToken, + protected string $baseUrl, + protected array $payload, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl . '/ship/rates'; } public function execute() : RatesCollection { try { - $responseArray = $this->api_request($this->url,$this->payload,$this->token,'POST',10,$this->flagshipFor,$this->version); + $responseArray = $this->api_request($this->apiUrl,$this->payload,$this->apiToken,'POST',10,$this->flagshipFor,$this->version); $responseObject = count((array)$responseArray["response"]) == 0 ? [] : $responseArray["response"]->content; $newQuotes = new RatesCollection(); $newQuotes->importRates($responseObject); diff --git a/Shipping/Requests/TrackShipmentRequest.php b/Shipping/Requests/TrackShipmentRequest.php index afe3261..db5322f 100644 --- a/Shipping/Requests/TrackShipmentRequest.php +++ b/Shipping/Requests/TrackShipmentRequest.php @@ -8,16 +8,22 @@ class TrackShipmentRequest extends ApiRequest{ - public function __construct(string $baseUrl,string $token,int $id, string $flagshipFor, string $version){ - $this->url= $baseUrl.'/ship/track?shipment_id='.$id; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + protected int $responseCode; + protected string $apiUrl; + + public function __construct( + protected string $baseUrl, + protected string $apiToken, + int $id, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl= $baseUrl.'/ship/track?shipment_id='.$id; } public function execute() { try{ - $trackShipment = $this->api_request($this->url,[],$this->token,'GET',30,$this->flagshipFor,$this->version); + $trackShipment = $this->api_request($this->apiUrl,[],$this->apiToken,'GET',30,$this->flagshipFor,$this->version); $this->responseCode = $trackShipment["httpcode"]; $trackingObject = count((array)$trackShipment["response"]) == 0 ? new \stdClass() : $trackShipment["response"]->content ; return new TrackShipment($trackingObject); diff --git a/Shipping/Requests/ValidateTokenRequest.php b/Shipping/Requests/ValidateTokenRequest.php index 1c04aa6..5ce7345 100644 --- a/Shipping/Requests/ValidateTokenRequest.php +++ b/Shipping/Requests/ValidateTokenRequest.php @@ -6,16 +6,20 @@ use Flagship\Shipping\Exceptions\ValidateTokenException; class ValidateTokenRequest extends ApiRequest{ - public function __construct(string $baseUrl,string $token, string $flagshipFor, string $version){ - $this->url = $baseUrl.'/check-token'; - $this->token = $token; - $this->flagshipFor = $flagshipFor; - $this->version = $version; + + protected string $apiUrl; + public function __construct( + protected string $baseUrl, + protected string $apiToken, + protected string $flagshipFor, + protected string $version + ){ + $this->apiUrl = $baseUrl.'/check-apiToken'; } public function execute() : int { try{ - $response = $this->api_request($this->url,[],$this->token,'GET',30,$this->flagshipFor,$this->version); + $response = $this->api_request($this->apiUrl,[],$this->apiToken,'GET',30,$this->flagshipFor,$this->version); return $response["httpcode"]; } catch(ApiException $e){ diff --git a/Shipping/Tests/AssociateShipmentTests.php b/Shipping/Tests/AssociateShipmentTests.php index 6bd6172..d1d3cbf 100755 --- a/Shipping/Tests/AssociateShipmentTests.php +++ b/Shipping/Tests/AssociateShipmentTests.php @@ -19,7 +19,7 @@ public function testExecute(){ protected function setUp() : void { $this->associateShipmentRequest = $this->getMockBuilder(AssociateShipmentRequest::class) ->setConstructorArgs(['testToken','localhost',20,[],'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); } } diff --git a/Shipping/Tests/AssociateToDepotTests.php b/Shipping/Tests/AssociateToDepotTests.php index fcaaf90..900ce68 100755 --- a/Shipping/Tests/AssociateToDepotTests.php +++ b/Shipping/Tests/AssociateToDepotTests.php @@ -19,7 +19,7 @@ public function testExecute(){ protected function setUp() : void { $this->associateToDepotRequest = $this->getMockBuilder(AssociateToDepotRequest::class) ->setConstructorArgs(['testToken','localhost',20,[],'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); } } diff --git a/Shipping/Tests/AvailableServicesCollectionTests.php b/Shipping/Tests/AvailableServicesCollectionTests.php index 299355f..f572619 100644 --- a/Shipping/Tests/AvailableServicesCollectionTests.php +++ b/Shipping/Tests/AvailableServicesCollectionTests.php @@ -8,6 +8,7 @@ use Flagship\Shipping\Exceptions\AvailableServicesException; class AvailableServicesCollectionTests extends TestCase{ + private $servicesCollection; public function testGetServicesByCourier(){ $this->assertNotEmpty($this->servicesCollection->getServicesByCourier('canpar')); diff --git a/Shipping/Tests/AvailableServicesTests.php b/Shipping/Tests/AvailableServicesTests.php index ff4def6..2bb1139 100755 --- a/Shipping/Tests/AvailableServicesTests.php +++ b/Shipping/Tests/AvailableServicesTests.php @@ -8,6 +8,9 @@ use Flagship\Shipping\Exceptions\AvailableServicesException; class AvailableServicesTests extends TestCase{ + private $availableServices; + private $getAvailableServices; + private $getAvailableServicesRequest; public function testGetServicesByCourier(){ $this->assertNotEmpty($this->availableServices->getServicesByCourier('canpar')); @@ -418,7 +421,7 @@ protected function setUp() : void { $this->getAvailableServicesRequest = $this->getMockBuilder(AvailableServicesRequest::class) ->setConstructorArgs(['testToken','localhost','test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->getAvailableServices = $this->getAvailableServicesRequest->execute(); diff --git a/Shipping/Tests/CancelManifestByIdTests.php b/Shipping/Tests/CancelManifestByIdTests.php index 1a62641..bff1c88 100755 --- a/Shipping/Tests/CancelManifestByIdTests.php +++ b/Shipping/Tests/CancelManifestByIdTests.php @@ -6,6 +6,8 @@ use Flagship\Shipping\Requests\CancelManifestByIdRequest; class CancelManifestByIdTests extends TestCase{ + + private $cancelManifestByIdRequest; public function testResponseCode(){ $this->assertNull($this->cancelManifestByIdRequest->getResponseCode()); @@ -19,7 +21,7 @@ public function testExecute(){ protected function setUp() : void { $this->cancelManifestByIdRequest = $this->getMockBuilder(CancelManifestByIdRequest::class) ->setConstructorArgs(['testToken','localhost',84,'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); } } diff --git a/Shipping/Tests/ConfirmManifestByIdTests.php b/Shipping/Tests/ConfirmManifestByIdTests.php index f5b0f30..83cb04b 100755 --- a/Shipping/Tests/ConfirmManifestByIdTests.php +++ b/Shipping/Tests/ConfirmManifestByIdTests.php @@ -12,6 +12,10 @@ class ConfirmManifestByIdTests extends TestCase{ + private $manifestRequest; + private $confirmManifestByIdRequest; + private $manifest; + public function testGetName(){ $this->assertNotNull($this->manifest->getName()); @@ -284,7 +288,7 @@ protected function setUp() : void { $this->confirmManifestByIdRequest = $this->getMockBuilder(ConfirmManifestByIdRequest::class) ->setConstructorArgs(['YuX5juWBvBB2oE1NohOc99qiaSutOM4C7tUpigGawkA','127.0.0.1:3002',23,'testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->manifestRequest = $this->confirmManifestByIdRequest->execute(); $this->manifest = new Manifest(json_decode($response)); diff --git a/Shipping/Tests/ConfirmShipmentTests.php b/Shipping/Tests/ConfirmShipmentTests.php index 849feb9..a321ae2 100644 --- a/Shipping/Tests/ConfirmShipmentTests.php +++ b/Shipping/Tests/ConfirmShipmentTests.php @@ -6,6 +6,8 @@ class ConfirmShipmentTests extends TestCase{ + private $confirmShipment; + public function testGetId(){ $this->assertNotEmpty($this->confirmShipment->getId()); $this->assertNotNull($this->confirmShipment->getId()); @@ -151,7 +153,7 @@ protected function setUp() : void { $this->confirmShipment = $this->getMockBuilder(Shipment::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/CreateManifestTests.php b/Shipping/Tests/CreateManifestTests.php index a7628b6..0fd4d1e 100755 --- a/Shipping/Tests/CreateManifestTests.php +++ b/Shipping/Tests/CreateManifestTests.php @@ -8,6 +8,10 @@ class CreateManifestTests extends TestCase{ + private $createManifestRequest; + private $manifestRequest; + private $manifest; + public function testGetName(){ $this->assertNotNull($this->manifest->getName()); $this->assertIsString($this->manifest->getName()); @@ -87,7 +91,7 @@ public function testGetAllPrices(){ protected function setUp() : void { $this->createManifestRequest = $this->getMockBuilder(CreateManifestRequest::class) ->setConstructorArgs(['jhdgjhsgfjhsd','https://www.flagshipcompany.com',["name" => "testManifest"],'testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->manifestRequest = $this->createManifestRequest->execute(); $response = '{ diff --git a/Shipping/Tests/CreatePickupTests.php b/Shipping/Tests/CreatePickupTests.php index 102a936..314f833 100755 --- a/Shipping/Tests/CreatePickupTests.php +++ b/Shipping/Tests/CreatePickupTests.php @@ -9,6 +9,10 @@ class CreatePickupTests extends TestCase{ + private $createPickupRequest; + private $createPickup; + private $pickup; + public function testGetId(){ $this->assertNotNull($this->pickup->getId()); $this->assertSame(1276084,$this->pickup->getId()); @@ -178,7 +182,7 @@ protected function setUp() : void { $this->createPickupRequest = $this->getMockBuilder(CreatePickupRequest::class) ->setConstructorArgs(['testToken','localhost',[],'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->createPickup = $this->createPickupRequest->execute(); $this->pickup = new Pickup(json_decode($response)); diff --git a/Shipping/Tests/EditPickupTests.php b/Shipping/Tests/EditPickupTests.php index 8943367..d30d8f6 100644 --- a/Shipping/Tests/EditPickupTests.php +++ b/Shipping/Tests/EditPickupTests.php @@ -6,7 +6,9 @@ class EditPickupTests extends TestCase{ - public function testGetId(){ + private $editPickup; + + public function testGetId(){ $this->assertNotEmpty($this->editPickup->getId()); $this->assertNotNull($this->editPickup->getId()); $this->assertSame(1085704,$this->editPickup->getId()); @@ -225,7 +227,7 @@ protected function setUp() : void { $this->editPickup = $this->getMockBuilder(Pickup::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/EditShipmentTests.php b/Shipping/Tests/EditShipmentTests.php index 353eae1..cea8946 100644 --- a/Shipping/Tests/EditShipmentTests.php +++ b/Shipping/Tests/EditShipmentTests.php @@ -5,6 +5,8 @@ use Flagship\Shipping\Objects\Shipment; class EditShipmentTests extends TestCase{ + + private $editShipment; public function testGetId(){ $this->assertNotEmpty($this->editShipment->getId()); @@ -401,7 +403,7 @@ protected function setUp() : void { $this->editShipment = $this->getMockBuilder(Shipment::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } } \ No newline at end of file diff --git a/Shipping/Tests/GetDhlEcommOpenShipmentsTests.php b/Shipping/Tests/GetDhlEcommOpenShipmentsTests.php index 4ece888..02f9006 100755 --- a/Shipping/Tests/GetDhlEcommOpenShipmentsTests.php +++ b/Shipping/Tests/GetDhlEcommOpenShipmentsTests.php @@ -9,6 +9,10 @@ class GetDhlEcommOpenShipmentsTests extends TestCase{ + private $getDhlEcommOpenShipmentsRequest; + private $openShipmentsRequest; + private $shipmentsList; + public function testGetById(){ $this->assertNotNull($this->shipmentsList->getById(3372152)); $this->assertInstanceOf(Shipment::class, $this->shipmentsList->getById(3372152)); @@ -61,7 +65,7 @@ public function testGetByReceiverPhone(){ public function testBySenderPhone(){ $this->expectException(GetShipmentListException::class); - $this->assertNull($this->getBySenderPhone('317746883')); + $this->assertNull($this->shipmentsList->getBySenderPhone('317746883')); } public function testGetBySenderCompany(){ @@ -74,10 +78,10 @@ public function testGetByReceiverCompany(){ $this->assertInstanceOf(GetShipmentListCollection::class, $this->shipmentsList->getByReceiverCompany("INRA")); } - protected function setUp(){ + protected function setUp() : void { $this->getDhlEcommOpenShipmentsRequest = $this->getMockBuilder(GetDhlEcommOpenShipmentsRequest::class) ->setConstructorArgs(['testToken','testUrl',23,'testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->openShipmentsRequest = $this->getDhlEcommOpenShipmentsRequest->execute(); diff --git a/Shipping/Tests/GetDhlEcommRatesTests.php b/Shipping/Tests/GetDhlEcommRatesTests.php index 32cc21b..9360a5e 100755 --- a/Shipping/Tests/GetDhlEcommRatesTests.php +++ b/Shipping/Tests/GetDhlEcommRatesTests.php @@ -10,6 +10,10 @@ class GetDhlEcommRatesTests extends TestCase{ + private $getDhlEcommRatesRequest; + private $ratesRequest; + private $rates; + public function testGetCheapest(){ $this->assertNotNull($this->rates->getCheapest()); $this->assertSame(31.18,$this->rates->getCheapest()->getTotal()); @@ -92,7 +96,7 @@ protected function setUp() : void { $this->getDhlEcommRatesRequest = $this->getMockBuilder(GetDhlEcommRatesRequest::class) ->setConstructorArgs(['testToken','localhost',['payload'],'testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->ratesRequest = $this->getDhlEcommRatesRequest->execute(); $this->rates = new RatesCollection(); diff --git a/Shipping/Tests/GetManifestByIdTests.php b/Shipping/Tests/GetManifestByIdTests.php index 91eb3ce..59fecd9 100755 --- a/Shipping/Tests/GetManifestByIdTests.php +++ b/Shipping/Tests/GetManifestByIdTests.php @@ -12,6 +12,10 @@ class GetManifestByIdTests extends TestCase{ + private $getManifestByIdRequest; + private $manifestRequest; + private $manifest; + public function testGetName(){ $this->assertNotNull($this->manifest->getName()); $this->assertSame('completeManifest',$this->manifest->getName()); @@ -310,7 +314,7 @@ protected function setUp() : void { $this->getManifestByIdRequest = $this->getMockBuilder(GetManifestByIdRequest::class) ->setConstructorArgs(['testToken','localhost',20,'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->manifestRequest = $this->getManifestByIdRequest->execute(); $this->manifest = new Manifest(json_decode($response)); diff --git a/Shipping/Tests/GetManifestsListTests.php b/Shipping/Tests/GetManifestsListTests.php index 779295e..6113a8a 100755 --- a/Shipping/Tests/GetManifestsListTests.php +++ b/Shipping/Tests/GetManifestsListTests.php @@ -10,6 +10,10 @@ class GetManifestsListTests extends TestCase{ + private $getManifestsListRequest; + private $manifestListsRequest; + private $manifestList; + public function testGetByStatus(){ $this->assertNotNull($this->manifestList->getByStatus('confirmed')); $this->assertSame(23,$this->manifestList->getByStatus('confirmed')->first()->getId()); @@ -56,7 +60,7 @@ protected function setUp() : void { $this->getManifestsListRequest = $this->getMockBuilder(GetManifestsListRequest::class) ->setConstructorArgs(['testToken','localhost','testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->manifestListsRequest = $this->getManifestsListRequest->execute(); $this->manifestList = new ManifestListCollection(); diff --git a/Shipping/Tests/GetPickupListTests.php b/Shipping/Tests/GetPickupListTests.php index 07da32a..b71f091 100755 --- a/Shipping/Tests/GetPickupListTests.php +++ b/Shipping/Tests/GetPickupListTests.php @@ -8,6 +8,9 @@ use Flagship\Shipping\Exceptions\GetPickupListException; class GetPickupListTests extends TestCase{ + private $getPickupListRequest; + private $getPickupList; + private $pickupList; public function testGetById(){ $this->assertNotNull($this->pickupList->getById(1276083)); @@ -198,7 +201,7 @@ protected function setUp() : void { ]'; $this->getPickupListRequest = $this->getMockBuilder(GetPickupListRequest::class) ->setConstructorArgs(['testToken','localhost','test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->getPickupList = $this->getPickupListRequest->execute(); $this->pickupList = new GetPickupListCollection(); diff --git a/Shipping/Tests/GetPickupListsCollectionTests.php b/Shipping/Tests/GetPickupListsCollectionTests.php index 7b752e0..8916096 100644 --- a/Shipping/Tests/GetPickupListsCollectionTests.php +++ b/Shipping/Tests/GetPickupListsCollectionTests.php @@ -7,7 +7,8 @@ class GetPickupListsCollectionTests extends TestCase{ - + private $pickupList; + public function testGetById(){ $this->assertNotEmpty($this->pickupList->getById(1085727)); diff --git a/Shipping/Tests/GetShipmentByIdTests.php b/Shipping/Tests/GetShipmentByIdTests.php index 61f7f1e..3afe10b 100755 --- a/Shipping/Tests/GetShipmentByIdTests.php +++ b/Shipping/Tests/GetShipmentByIdTests.php @@ -8,6 +8,10 @@ class GetShipmentByIdTests extends TestCase{ + private $getShipmentByIdRequest; + private $getShipment; + private $shipment; + public function testGetId(){ $this->assertNotNull($this->shipment->getId()); $this->assertSame(3372194,$this->shipment->getId()); @@ -81,7 +85,7 @@ public function testGetSenderPhoneExt(){ public function testGetSenderDetails(){ $this->assertNotNull($this->shipment->getSenderDetails()); - $this->assertInternalType('array',$this->shipment->getSenderDetails()); + $this->assertIsArray($this->shipment->getSenderDetails()); } public function testGetReceiverName(){ @@ -145,7 +149,7 @@ public function testGetReceiverPhoneExt(){ public function testGetReceiverDetails(){ $this->assertNotNull($this->shipment->getReceiverDetails()); - $this->assertInternalType('array',$this->shipment->getReceiverDetails()); + $this->assertIsArray($this->shipment->getReceiverDetails()); } public function testGetReference(){ @@ -228,7 +232,7 @@ public function testGetPackageType(){ public function testGetItemsDetails(){ $this->assertNotNull($this->shipment->getItemsDetails()); - $this->assertInternalType('array',$this->shipment->getItemsDetails()); + $this->assertIsArray($this->shipment->getItemsDetails()); } public function testGetSubtotal(){ @@ -389,7 +393,7 @@ protected function setUp() : void { $this->getShipmentByIdRequest = $this->getMockBuilder(GetShipmentByIdRequest::class) ->setConstructorArgs(['testToken','localhost','test','1.0.11',3351627]) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->getShipment = $this->getShipmentByIdRequest->execute(); $this->shipment = new Shipment(json_decode($response)); diff --git a/Shipping/Tests/GetShipmentListTests.php b/Shipping/Tests/GetShipmentListTests.php index 3b2a5d9..95b5165 100755 --- a/Shipping/Tests/GetShipmentListTests.php +++ b/Shipping/Tests/GetShipmentListTests.php @@ -10,6 +10,10 @@ class GetShipmentListTests extends TestCase{ + private $getShipmentListRequest; + private $shipmentListRequest; + private $shipmentList; + public function testGetById(){ $this->expectException(GetShipmentListException::class); $this->assertNotNull($this->shipmentList->getById(253858)); @@ -1044,7 +1048,7 @@ protected function setUp() : void { $this->getShipmentListRequest = $this->getMockBuilder(GetShipmentListRequest::class) ->setConstructorArgs(['testToken','localhost','test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->shipmentListRequest = $this->getShipmentListRequest->execute(); $this->shipmentList = new GetShipmentListCollection(); diff --git a/Shipping/Tests/GetShipmentListsCollectionTests.php b/Shipping/Tests/GetShipmentListsCollectionTests.php index 683075e..55eb458 100644 --- a/Shipping/Tests/GetShipmentListsCollectionTests.php +++ b/Shipping/Tests/GetShipmentListsCollectionTests.php @@ -8,6 +8,8 @@ class GetShipmentListsCollectionTests extends TestCase{ + private $shipmentsCollection; + public function testGetById(){ $this->assertNotNull($this->shipmentsCollection->getById(2950191)); $this->assertInstanceOf(Shipment::class , $this->shipmentsCollection->getById(2950191)); diff --git a/Shipping/Tests/ManifestTests.php b/Shipping/Tests/ManifestTests.php index ac3a206..ab1a79c 100644 --- a/Shipping/Tests/ManifestTests.php +++ b/Shipping/Tests/ManifestTests.php @@ -8,6 +8,8 @@ class ManifestTests extends TestCase{ + private $manifest; + public function testGetName(){ $this->assertNotNull($this->manifest->getName()); $this->assertSame("completeManifest", $this->manifest->getName()); @@ -294,7 +296,7 @@ protected function setup() : void { $this->manifest = $this->getMockBuilder(Manifest::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/PackingTests.php b/Shipping/Tests/PackingTests.php index 81bbc82..be9495e 100644 --- a/Shipping/Tests/PackingTests.php +++ b/Shipping/Tests/PackingTests.php @@ -6,6 +6,8 @@ class PackingTests extends TestCase{ + private $packing; + public function testGetBoxModel(){ $this->assertNotNull($this->packing->getBoxModel()); $this->assertSame("Le grande box", $this->packing->getBoxModel()); @@ -53,7 +55,7 @@ protected function setUp() : void { $this->packing = $this->getMockBuilder(Packing::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/PickupTests.php b/Shipping/Tests/PickupTests.php index 9d3ce3f..3bf0acb 100644 --- a/Shipping/Tests/PickupTests.php +++ b/Shipping/Tests/PickupTests.php @@ -6,6 +6,7 @@ class PickupTests extends TestCase{ + private $pickup; public function testGetId(){ $this->assertNotNull($this->pickup->getId()); $this->assertSame(1085501, $this->pickup->getId()); @@ -173,7 +174,7 @@ protected function setUp() : void { $this->pickup = $this->getMockBuilder(Pickup::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/PrepareShipmentTests.php b/Shipping/Tests/PrepareShipmentTests.php index eda7916..e932c4a 100644 --- a/Shipping/Tests/PrepareShipmentTests.php +++ b/Shipping/Tests/PrepareShipmentTests.php @@ -7,6 +7,8 @@ class PrepareShipmentTests extends TestCase{ + private $preparedShipment; + public function testGetId(){ $this->assertNotEmpty($this->preparedShipment->getId()); $this->assertNotNull($this->preparedShipment->getId()); @@ -400,7 +402,7 @@ protected function setUp() : void { $this->preparedShipment = $this->getMockBuilder(Shipment::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } } \ No newline at end of file diff --git a/Shipping/Tests/QuoteTests.php b/Shipping/Tests/QuoteTests.php index 6c9666f..57a6376 100755 --- a/Shipping/Tests/QuoteTests.php +++ b/Shipping/Tests/QuoteTests.php @@ -9,6 +9,10 @@ class QuoteTests extends TestCase{ + private $getQuoteRequest; + private $quoteRequest; + private $rates; + public function testGetCheapest(){ $this->assertNotNull($this->rates->getCheapest()); $this->assertInstanceOf(Rate::class,$this->rates->getCheapest()); @@ -365,7 +369,7 @@ protected function setUp() : void { $this->getQuoteRequest = $this->getMockBuilder(QuoteRequest::class) ->setConstructorArgs(['testToken','localhost',[],'test','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); $this->quoteRequest = $this->getQuoteRequest->execute(); $this->rates = new RatesCollection(); diff --git a/Shipping/Tests/RateTests.php b/Shipping/Tests/RateTests.php index 2a071d0..c5b36e4 100644 --- a/Shipping/Tests/RateTests.php +++ b/Shipping/Tests/RateTests.php @@ -6,6 +6,8 @@ class RateTests extends TestCase{ + private $rate; + public function testGetTotal(){ $this->assertNotNull($this->rate->getTotal()); $this->assertSame(64.78, $this->rate->getTotal()); @@ -96,7 +98,7 @@ protected function setUp() : void { $this->rate = $this->getMockBuilder(Rate::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } diff --git a/Shipping/Tests/RatesCollectionTests.php b/Shipping/Tests/RatesCollectionTests.php index 499a570..e57c6ab 100644 --- a/Shipping/Tests/RatesCollectionTests.php +++ b/Shipping/Tests/RatesCollectionTests.php @@ -8,6 +8,8 @@ class RatesCollectionTests extends TestCase{ + private $ratesCollection; + public function testGetCheapest(){ $this->assertNotEmpty($this->ratesCollection->getCheapest()); $this->assertNotNull($this->ratesCollection->getCheapest()); diff --git a/Shipping/Tests/ShipmentTests.php b/Shipping/Tests/ShipmentTests.php index ad3e8bb..afe5967 100644 --- a/Shipping/Tests/ShipmentTests.php +++ b/Shipping/Tests/ShipmentTests.php @@ -6,6 +6,8 @@ class ShipmentTests extends TestCase{ + private $shipment; + public function testGetId(){ $this->assertNotNull($this->shipment->getId()); $this->assertSame(2950191, $this->shipment->getId()); @@ -277,7 +279,7 @@ protected function setup() : void { }'; $this->shipment = $this->getMockBuilder(Shipment::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } } diff --git a/Shipping/Tests/TrackShipmentTests.php b/Shipping/Tests/TrackShipmentTests.php index d20a05b..e3ddf0a 100644 --- a/Shipping/Tests/TrackShipmentTests.php +++ b/Shipping/Tests/TrackShipmentTests.php @@ -6,6 +6,8 @@ class TrackShipmentTests extends TestCase{ + private $trackShipment; + public function testGetCurrentStatus(){ $this->assertNotNull($this->trackShipment->getCurrentStatus()); $this->assertSame('T',$this->trackShipment->getCurrentStatus()); @@ -34,7 +36,7 @@ protected function setup() : void { }'; $this->trackShipment = $this->getMockBuilder(TrackShipment::class) ->setConstructorArgs([json_decode($response)]) - ->setMethods(['__construct']) + ->onlyMethods(['__construct']) ->getMock(); } } diff --git a/Shipping/Tests/ValidateTokenTests.php b/Shipping/Tests/ValidateTokenTests.php index 62092e3..982582b 100755 --- a/Shipping/Tests/ValidateTokenTests.php +++ b/Shipping/Tests/ValidateTokenTests.php @@ -5,19 +5,17 @@ class ValidateTokenTests extends TestCase{ + private $validateTokenRequest; + public function testExecute(){ $this->assertNotNull($this->validateTokenRequest->execute()); $this->assertSame(0,$this->validateTokenRequest->execute()); } - public function testGetResponseCode(){ - $this->assertNull($this->validateTokenRequest->getResponseCode()); - } - protected function setUp() : void { $this->validateTokenRequest = $this->getMockBuilder(ValidateTokenRequest::class) ->setConstructorArgs(['localhost','testToken','testing','1.0.11']) - ->setMethods(['execute']) + ->onlyMethods(['execute']) ->getMock(); } } \ No newline at end of file diff --git a/composer.json b/composer.json index 80760ad..64bdbb6 100644 --- a/composer.json +++ b/composer.json @@ -11,10 +11,10 @@ ] }, "require-dev": { - "phpunit/phpunit": ">=6.5" + "phpunit/phpunit": ">=9.6" }, "require": { "php": ">=7.1", - "tightenco/collect": ">=5.8" + "illuminate/collections": ">=10.0" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 485b4ea..142d7b4 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,27 @@ + colors="true" + displayDetailsOnTestsThatTriggerDeprecations="true" + displayDetailsOnTestsThatTriggerErrors="false" + displayDetailsOnTestsThatTriggerNotices="false" + displayDetailsOnTestsThatTriggerWarnings="false" + displayDetailsOnPhpunitDeprecations="true" + > ./Shipping/Tests - + From ebe110f35ba484e32db5d00fb6621ec4d3455edf Mon Sep 17 00:00:00 2001 From: radua Date: Tue, 25 Mar 2025 11:38:07 -0400 Subject: [PATCH 2/2] Update Flagship.php --- Shipping/Flagship.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Shipping/Flagship.php b/Shipping/Flagship.php index ae9a48c..ac59874 100644 --- a/Shipping/Flagship.php +++ b/Shipping/Flagship.php @@ -39,12 +39,12 @@ class Flagship{ - public function __construct(string $apiToken, string $apiUrl, string $flagshipFor='', string $version=''){ - $this->apiUrl = $apiUrl; - $this->apiToken = $apiToken; - $this->flagshipFor = $flagshipFor; - $this->version = $version; - } + public function __construct( + protected string $apiToken, + protected string $apiUrl, + protected string $flagshipFor='', + protected string $version='' + ){} public function availableServicesRequest() : AvailableServicesRequest { $availableServicesRequest = new AvailableServicesRequest($this->apiToken,$this->apiUrl,$this->flagshipFor,$this->version);