Skip to content

Commit 602bbcb

Browse files
committed
Added GetShipping. Allow PHP8. Added GitHub actions.
1 parent dd0a7fd commit 602bbcb

34 files changed

+411
-92
lines changed

Diff for: .dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor

Diff for: .github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @ekyna

Diff for: .github/workflows/build.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build
2+
3+
on:
4+
push: ~
5+
pull_request: ~
6+
release:
7+
types: [created]
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
13+
name: "PHP ${{ matrix.php }}, Symfony ${{ matrix.symfony }}"
14+
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1]
19+
symfony: [^3.4, ^4.4, ^5.2, ^6.0]
20+
exclude:
21+
- { php: 7.1, symfony: ^5.2 }
22+
- { php: 7.1, symfony: ^6.0 }
23+
- { php: 7.2, symfony: ^6.0 }
24+
- { php: 7.3, symfony: ^6.0 }
25+
- { php: 7.4, symfony: ^6.0 }
26+
27+
env:
28+
APP_ENV: test
29+
30+
steps:
31+
-
32+
uses: actions/checkout@v2
33+
34+
-
35+
name: Setup PHP
36+
uses: shivammathur/setup-php@v2
37+
with:
38+
php-version: "${{ matrix.php }}"
39+
extensions: intl
40+
tools: symfony
41+
coverage: none
42+
43+
-
44+
name: Get Composer cache directory
45+
id: composer-cache
46+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
47+
48+
-
49+
name: Cache Composer
50+
uses: actions/cache@v2
51+
with:
52+
path: ${{ steps.composer-cache.outputs.dir }}
53+
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json **/composer.lock') }}
54+
restore-keys: |
55+
${{ runner.os }}-php-${{ matrix.php }}-composer-
56+
-
57+
name: Restrict Symfony version
58+
if: matrix.symfony != ''
59+
run: |
60+
composer global require --no-progress --no-scripts --no-plugins "symfony/flex:^1.10"
61+
composer config extra.symfony.require "${{ matrix.symfony }}"
62+
63+
-
64+
name: Install PHP dependencies
65+
run: composer install --no-interaction
66+
67+
-
68+
name: Run analysis
69+
run: composer validate --strict
70+
71+
-
72+
name: Run PHPUnit
73+
run: vendor/bin/phpunit --colors=always

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/.phpunit.result.cache
12
/examples/config.php
23
/examples/tmp
34
/bin

Diff for: .travis.yml

-23
This file was deleted.

Diff for: Dockerfile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM php:8.1-cli
2+
3+
COPY --from=mlocati/php-extension-installer:latest /usr/bin/install-php-extensions /usr/local/bin/
4+
5+
RUN install-php-extensions @composer gd soap \
6+
&& docker-php-source delete \
7+
&& rm /usr/local/bin/install-php-extensions
8+
9+
COPY . /usr/src/myapp
10+
11+
WORKDIR /usr/src/myapp
12+
13+
RUN composer install --no-dev --no-progress

Diff for: README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
PHP component for DPD shipment.
44

5-
[![Build Status](https://travis-ci.org/ekyna/Dpd.svg?branch=master)](https://travis-ci.org/ekyna/Dpd)
5+
[![Build](https://github.com/ekyna/dpd/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/ekyna/dpd/actions/workflows/build.yml)
66

77

88
## Installation
@@ -21,3 +21,7 @@ _You will need credentials and IP address authorization. Please refer to your DP
2121
* [GetShipment](https://github.com/ekyna/Dpd/blob/master/examples/get-shipment.php)
2222
* [GetLabel](https://github.com/ekyna/Dpd/blob/master/examples/get-label.php)
2323

24+
## Testing with Docker
25+
26+
docker build . -t dpd-test
27+
docker run -it --rm dpd-test php examples/get-shipping.php

Diff for: composer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
"require": {
2020
"php": ">=7.1",
2121
"ext-soap": "*",
22+
"ext-gd": "*",
2223
"guzzlehttp/guzzle": "^6.3"
2324
},
2425
"require-dev": {
25-
"phpunit/phpunit": "~7.5"
26+
"phpunit/phpunit": "^7.0|^8.0"
2627
},
2728
"autoload": {
2829
"psr-4": {
2930
"Ekyna\\Component\\Dpd\\": "src/"
3031
}
3132
},
33+
"autoload-dev": {
34+
"psr-4": {
35+
"Ekyna\\Component\\Dpd\\Tests\\": "tests/"
36+
}
37+
},
3238
"extra": {
3339
"branch-alias": {
3440
"dev-master": "1.0.x-dev"

Diff for: examples/create-shipment-with-labels.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,10 @@
109109
echo get_class($result) . "\n";
110110

111111
// Get shipments
112-
$idx = 1;
112+
$idx = 0;
113113
/** @var \Ekyna\Component\Dpd\EPrint\Model\Shipment $shipment */
114114
foreach ($result->shipments as $shipment) {
115-
echo get_class($shipment) . "\n";
116-
115+
$idx++;
117116
// Tracking url:
118117
echo "Shipment#$idx tracking url: {$shipment->getTrackingUrl()}\n";
119118
}

Diff for: examples/create-shipment.php

-9
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,3 @@
9797
// Tracking url:
9898
echo "Shipment #$idx tracking url: {$shipment->getTrackingUrl()}\n";
9999
}
100-
101-
102-
103-
104-
/*$result = $api->isAlive();
105-
echo var_export($result, true);
106-
107-
$result = $api->getInfo();
108-
echo var_export($result, true);*/

Diff for: examples/get-shipping.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
use Ekyna\Component\Dpd\Exception;
6+
use Ekyna\Component\Dpd\EPrint;
7+
8+
/* ---------------- Client and API ---------------- */
9+
10+
require __DIR__ . '/config.php';
11+
12+
$api = new EPrint\Api($ePrintConfig);
13+
14+
/* ---------------- Create request ---------------- */
15+
16+
$request = new EPrint\Request\GetShippingRequest();
17+
18+
$request->date = '31.01.2022';
19+
20+
$request->customer = new EPrint\Model\Customer();
21+
$request->customer->number = $usePredict ? $predictNumber : $classicNumber;
22+
$request->customer->countrycode = $countryCode;
23+
$request->customer->centernumber = $centerNumber;
24+
25+
/* ---------------- Get response ---------------- */
26+
27+
// Use API helper
28+
try {
29+
/** @var \Ekyna\Component\Dpd\EPrint\Response\GetShippingResponse $response */
30+
$response = $api->GetShipping($request);
31+
} catch (Exception\ExceptionInterface $e) {
32+
echo "Error: " . $e->getMessage();
33+
if ($debug && $e instanceof Exception\ClientException) {
34+
echo "\nRequest:\n" . $e->request;
35+
echo "\nResponse:\n" . $e->response;
36+
}
37+
exit();
38+
}
39+
echo get_class($response) . "\n";
40+
41+
// Get result
42+
$result = $response->GetShippingResult;
43+
echo get_class($result) . "\n";
44+
45+
/** @var \Ekyna\Component\Dpd\EPrint\Model\Shipping $shipping */
46+
foreach ($result->shippings->Shipping as $shipping) {
47+
$tracking = substr($shipping->shipment, 6);
48+
$reference = $shipping->reference;
49+
50+
echo "$reference: $tracking\n";
51+
}

Diff for: phpunit.xml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/5.4/phpunit.xsd"
4-
bootstrap="tests/bootstrap.php"
54
backupGlobals="false"
65
backupStaticAttributes="false"
76
beStrictAboutCoversAnnotation="true"

Diff for: src/EPrint/Api.php

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @method Response\TerminateCollectionRequestResponse TerminateCollectionRequest(Request\TerminateCollectionRequestRequest $request)
2121
* @method Response\GetShipmentResponse GetShipment(Request\ShipmentRequest $request)
2222
* @method Response\GetLabelResponse GetLabel(Request\ReceiveLabelRequest $request)
23+
* @method Response\GetShippingResponse GetShipping(Request\GetShippingRequest $request)
2324
*/
2425
class Api
2526
{

Diff for: src/EPrint/Client.php

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public function __construct(
7878
'ShipmentDataExtended' => Model\ShipmentDataExtended::class,
7979
'ShipmentWithLabels' => Model\ShipmentWithLabels::class,
8080
'ShipmentsWithLabels' => Model\ShipmentsWithLabels::class,
81+
'Shipping' => Model\Shipping::class,
8182
'CreateShipmentResponse' => Response\CreateShipmentResponse::class,
8283
'CreateMultiShipmentResponse' => Response\CreateMultiShipmentResponse::class,
8384
'CreateShipmentWithLabelsResponse' => Response\CreateShipmentWithLabelsResponse::class,
@@ -87,6 +88,7 @@ public function __construct(
8788
'TerminateCollectionRequestResponse' => Response\TerminateCollectionRequestResponse::class,
8889
'GetLabelResponse' => Response\GetLabelResponse::class,
8990
'GetShipmentResponse' => Response\GetShipmentResponse::class,
91+
'GetShippingResponse' => Response\GetShippingResponse::class,
9092
],
9193
];
9294

Diff for: src/EPrint/Method/GetShipping.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
declare (strict_types=1);
3+
4+
namespace Ekyna\Component\Dpd\EPrint\Method;
5+
6+
use Ekyna\Component\Dpd\EPrint\Request\GetShippingRequest;
7+
8+
/**
9+
* Class GetShipping
10+
* @package Ekyna\Component\Dpd
11+
* @author Etienne Dauvergne <contact@ekyna.com>
12+
*/
13+
class GetShipping extends AbstractMethod
14+
{
15+
/**
16+
* @inheritdoc
17+
*/
18+
protected function getMethodName(): string
19+
{
20+
return 'GetShipping';
21+
}
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
protected function getRequestClass(): string
27+
{
28+
return GetShippingRequest::class;
29+
}
30+
}

Diff for: src/EPrint/Model/ArrayOfShipping.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare (strict_types=1);
3+
4+
namespace Ekyna\Component\Dpd\EPrint\Model;
5+
6+
use Ekyna\Component\Dpd\OutputInterface;
7+
8+
/**
9+
* Class ArrayOfShipping
10+
* @package Ekyna\Component\Dpd\Response
11+
* @author Etienne Dauvergne <contact@ekyna.com>
12+
*/
13+
class ArrayOfShipping extends \ArrayObject implements OutputInterface
14+
{
15+
/**
16+
* @var Shipping|Shipping[]
17+
*/
18+
public $Shipping;
19+
20+
21+
/**
22+
* @inheritdoc
23+
*/
24+
public function initialize(): void
25+
{
26+
if ($this->Shipping) {
27+
$data = is_array($this->Shipping) ? array_values($this->Shipping) : [$this->Shipping];
28+
$this->__construct($data);
29+
unset($this->Shipping);
30+
}
31+
}
32+
}

Diff for: src/EPrint/Model/GetShippingResult.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Ekyna\Component\Dpd\EPrint\Model;
6+
7+
use Ekyna\Component\Dpd\OutputInterface;
8+
9+
/**
10+
* Class GetShippingResult
11+
* @package Ekyna\Component\Dpd\EPrint\Model
12+
* @author Étienne Dauvergne <contact@ekyna.com>
13+
*/
14+
class GetShippingResult implements OutputInterface
15+
{
16+
/**
17+
* @var ArrayOfShipping
18+
*/
19+
public $shippings;
20+
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
public function initialize(): void
26+
{
27+
if ($this->shippings) {
28+
$this->shippings->initialize();
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)