Skip to content

Commit

Permalink
feat: add repositories and requests (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen authored Jul 4, 2022
1 parent b95f737 commit 03b23f1
Show file tree
Hide file tree
Showing 64 changed files with 2,141 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: 'Run tests'
if: github.actor != 'dependabot[bot]'
run: docker run -v $(pwd):/app ${{ steps.docker.outputs.tagged-image }}
run: docker run ${{ steps.docker.outputs.tagged-image }}

- name: 'Get coverage file from container'
if: github.actor != 'dependabot[bot]'
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.phpunit.result.cache
.yarn-*.log
composer.lock
coverage.xml

/coverage/
/node_modules/
Expand All @@ -28,4 +29,3 @@ composer.lock
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

18 changes: 16 additions & 2 deletions .idea/pdk.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/php-test-framework.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/runConfigurations/All_tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ ARG PHP_VERSION=7.4
###
FROM ghcr.io/myparcelnl/php-xd:${PHP_VERSION} AS test

COPY composer.json ./
COPY composer.json phpunit.xml ./
COPY tests/ ./tests/
COPY src/ ./src/

RUN composer install
RUN composer install --dev

CMD ["vendor/bin/pest", "--coverage-clover", "coverage.xml"]

Expand Down
17 changes: 10 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "MyParcel Plugin Development Kit",
"type": "library",
"homepage": "https://www.myparcel.nl",
"minimum-stability": "dev",
"require": {
"myparcelnl/sdk": "^7.1",
"php": ">=7.1.0",
"myparcelnl/sdk": "^7.1"
"php-di/php-di": "~6.0.0",
"guzzlehttp/guzzle": "^7.4"
},
"require-dev": {
"pestphp/pest": "^1.21",
Expand All @@ -20,14 +21,16 @@
"MyParcelNL\\Pdk\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"MyParcelNL\\Pdk\\": "tests/Unit",
"MyParcelNL\\Pdk\\Tests\\": "tests"
}
},
"authors": [
{
"name": "Edie Lemoine",
"email": "[email protected]"
},
{
"name": "Joeri van Veen",
"email": "[email protected]"
"email": "[email protected]"
}
],
"config": {
Expand Down
25 changes: 14 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" cacheResult="true"
executionOrder="depends,defects">
<coverage>
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude>
<file>./src/Api/MyParcelApiService.php</file>
</exclude>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
<env name="TEST" value="true" />
</php>
</phpunit>
15 changes: 15 additions & 0 deletions src/Account/Platform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\Account;

class Platform
{
public const FLESPAKKET_ID = 3;
public const FLESPAKKET_NAME = 'flespakket';
public const MYPARCEL_ID = 1;
public const MYPARCEL_NAME = 'myparcel';
public const SENDMYPARCEL_ID = 2;
public const SENDMYPARCEL_NAME = 'belgie';
}
28 changes: 28 additions & 0 deletions src/Account/Repository/AccountRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\Account\Repository;

use MyParcelNL\Pdk\Account\Request\GetAccountsRequest;
use MyParcelNL\Pdk\Account\Response\GetAccountsResponseWithBody;
use MyParcelNL\Pdk\Base\Repository\AbstractRepository;
use MyParcelNL\Sdk\src\Model\Account\Account;

class AccountRepository extends AbstractRepository
{
/**
* @return \MyParcelNL\Sdk\src\Model\Account\Account
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \MyParcelNL\Sdk\src\Exception\ApiException
*/
public function getAccount(): Account
{
return $this->retrieve('account', function () {
/** @var GetAccountsResponseWithBody $response */
$response = $this->api->doRequest(new GetAccountsRequest(), GetAccountsResponseWithBody::class);

return $response->getAccount();
});
}
}
33 changes: 33 additions & 0 deletions src/Account/Repository/CarrierOptionsRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\Account\Repository;

use MyParcelNL\Pdk\Account\Request\GetCarrierOptionsRequest;
use MyParcelNL\Pdk\Account\Response\GetCarrierOptionsResponseWithBody;
use MyParcelNL\Pdk\Base\Repository\AbstractRepository;
use MyParcelNL\Sdk\src\Support\Collection;

class CarrierOptionsRepository extends AbstractRepository
{
/**
* @param int $carrierId
*
* @return \MyParcelNL\Sdk\src\Support\Collection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \MyParcelNL\Sdk\src\Exception\ApiException
*/
public function getCarrierOptions(int $carrierId): Collection
{
return $this->retrieve('carrier_options', function () use ($carrierId) {
/** @var \MyParcelNL\Pdk\Account\Response\GetCarrierOptionsResponseWithBody $response */
$response = $this->api->doRequest(
new GetCarrierOptionsRequest($carrierId),
GetCarrierOptionsResponseWithBody::class
);

return $response->getCarrierOptions();
});
}
}
58 changes: 58 additions & 0 deletions src/Account/Repository/ShopCarrierConfigurationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\Account\Repository;

use MyParcelNL\Pdk\Account\Request\GetShopCarrierConfigurationRequest;
use MyParcelNL\Pdk\Account\Request\GetShopCarrierConfigurationsRequest;
use MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody;
use MyParcelNL\Pdk\Base\Repository\AbstractRepository;
use MyParcelNL\Sdk\src\Model\Account\CarrierConfiguration;
use MyParcelNL\Sdk\src\Support\Collection;

class ShopCarrierConfigurationRepository extends AbstractRepository
{
/**
* @param int $shopId
* @param string $carrier
*
* @return \MyParcelNL\Sdk\src\Model\Account\CarrierConfiguration
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \MyParcelNL\Sdk\src\Exception\ApiException
*/
public function getCarrierConfiguration(int $shopId, string $carrier): CarrierConfiguration
{
return $this->retrieve('carrier_configurations', function () use ($carrier, $shopId) {
/** @var \MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody $response */
$response = $this->api->doRequest(
new GetShopCarrierConfigurationRequest($shopId, $carrier),
GetShopCarrierConfigurationsResponseWithBody::class
);

return $response
->getCarrierConfigurations()
->first();
});
}

/**
* @param int $shopId
*
* @return \MyParcelNL\Sdk\src\Support\Collection
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \MyParcelNL\Sdk\src\Exception\ApiException
*/
public function getCarrierConfigurations(int $shopId): Collection
{
return $this->retrieve('carrier_configurations', function () use ($shopId) {
/** @var \MyParcelNL\Pdk\Account\Response\GetShopCarrierConfigurationsResponseWithBody $response */
$response = $this->api->doRequest(
new GetShopCarrierConfigurationsRequest($shopId),
GetShopCarrierConfigurationsResponseWithBody::class
);

return $response->getCarrierConfigurations();
});
}
}
27 changes: 27 additions & 0 deletions src/Account/Repository/ShopRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace MyParcelNL\Pdk\Account\Repository;

use MyParcelNL\Pdk\Account\Request\GetShopsRequest;
use MyParcelNL\Pdk\Account\Response\GetShopsResponseWithBody;
use MyParcelNL\Pdk\Base\Repository\AbstractRepository;
use MyParcelNL\Sdk\src\Model\Account\Shop;

class ShopRepository extends AbstractRepository
{
/**
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \MyParcelNL\Sdk\src\Exception\ApiException
*/
public function getShop(): Shop
{
return $this->retrieve('shop', function () {
/** @var \MyParcelNL\Pdk\Account\Response\GetShopsResponseWithBody $response */
$response = $this->api->doRequest(new GetShopsRequest(), GetShopsResponseWithBody::class);

return $response->getShop();
});
}
}
Loading

0 comments on commit 03b23f1

Please sign in to comment.