-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c5c3c6
commit 43cfb5b
Showing
61 changed files
with
2,686 additions
and
1,978 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use MyParcelNL\Sdk\src\Factory\ConsignmentFactory; | ||
use MyParcelNL\Sdk\src\Helper\MyParcelCollection; | ||
use MyParcelNL\Sdk\src\Model\Carrier\CarrierRedJePakketje; | ||
use MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint; | ||
use MyParcelNL\Sdk\src\Services\Web\RedJePakketjeDropOffPointWebService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DropOffPointTest extends TestCase | ||
{ | ||
public function provideTestDropOffPointData(): array | ||
{ | ||
return [ | ||
'RedJePakketje' => [ | ||
[ | ||
'cc' => 'NL', | ||
'company' => 'MyParcel', | ||
'person' => 'Mr. Parcel', | ||
'full_street' => 'Meander 631', | ||
'postal_code' => '6825ME', | ||
'city' => 'Arnhem', | ||
'phone' => '123456', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
* @throws \Exception | ||
* @dataProvider provideTestDropOffPointData | ||
*/ | ||
public function testDropOffPoint(array $consignmentTest): void | ||
{ | ||
$consignment = ConsignmentFactory::createByCarrierId(CarrierRedJePakketje::getId()) | ||
->setApiKey(getenv('API_KEY')) | ||
->setCountry($consignmentTest['cc']) | ||
->setPerson($consignmentTest['person']) | ||
->setCompany($consignmentTest['company']) | ||
->setFullStreet($consignmentTest['full_street']) | ||
->setPostalCode($consignmentTest['postal_code']) | ||
->setCity($consignmentTest['city']) | ||
->setEmail('[email protected]') | ||
->setPhone($consignmentTest['phone']); | ||
|
||
$dropOffPoints = (new RedJePakketjeDropOffPointWebService()) | ||
->setApiKey(getenv('API_KEY')) | ||
->getDropOffPoints($consignmentTest['postal_code']); | ||
|
||
self::assertNotEmpty($dropOffPoints); | ||
|
||
$dropOffPoint = (new DropOffPoint()) | ||
->setBoxNumber() | ||
->setCc($dropOffPoints[0]['cc'] ?? null) | ||
->setCity($dropOffPoints[0]['city'] ?? null) | ||
->setLocationCode($dropOffPoints[0]['location_code'] ?? null) | ||
->setLocationName($dropOffPoints[0]['location_name'] ?? null) | ||
->setNumber($dropOffPoints[0]['number'] ?? null) | ||
->setNumberSuffix($dropOffPoints[0]['number_suffix'] ?? null) | ||
->setPostalCode($dropOffPoints[0]['postal_code'] ?? null) | ||
->setRegion($dropOffPoints[0]['region'] ?? null) | ||
->setRetailNetworkId($dropOffPoints[0]['retail_network_id'] ?? null) | ||
->setState($dropOffPoints[0]['state'] ?? null) | ||
->setStreet($dropOffPoints[0]['street'] ?? null); | ||
|
||
$consignment->setDropOffPoint($dropOffPoint); | ||
|
||
$collection = new MyParcelCollection(); | ||
$collection->addConsignment($consignment); | ||
$collection->setLinkOfLabels(); | ||
|
||
self::assertEquals( | ||
true, | ||
preg_match( | ||
"#^https://api(\.[a-z]+)?\.myparcel\.nl/pdfs#", | ||
$collection->getLinkOfLabels() | ||
), | ||
'Can\'t get link of PDF' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Sdk\src\Services; | ||
|
||
use MyParcelNL\Sdk\src\Services\Web\AccountWebService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AccountServiceTest extends TestCase | ||
{ | ||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
*/ | ||
public function testGetAccount(): void | ||
{ | ||
$result = (new AccountWebService()) | ||
->setApiKey(getenv('API_KEY')) | ||
->getAccount(); | ||
|
||
self::assertArrayHasKey('id', $result->toArray()); | ||
self::assertArrayHasKey('platform_id', $result->toArray()); | ||
self::assertArrayHasKey('shops', $result->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Sdk\src\Services; | ||
|
||
use MyParcelNL\Sdk\src\Model\Account\Shop; | ||
use MyParcelNL\Sdk\src\Services\Web\AccountWebService; | ||
use MyParcelNL\Sdk\src\Services\Web\CarrierConfigurationWebService; | ||
use MyParcelNL\Sdk\src\Services\Web\CarrierOptionsWebService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CarrierConfigurationServiceTest extends TestCase | ||
{ | ||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
*/ | ||
public function testGetConfiguration(): void | ||
{ | ||
$accountService = (new AccountWebService())->setApiKey(getenv('API_KEY')); | ||
$carrierOptionsService = (new CarrierOptionsWebService())->setApiKey(getenv('API_KEY')); | ||
|
||
$accountService->getAccount() | ||
->getShops() | ||
->first(static function (Shop $shop) use ($carrierOptionsService) { | ||
$carriers = $carrierOptionsService->getCarrierOptions($shop->getId()); | ||
$carrierConfigurationService = (new CarrierConfigurationWebService())->setApiKey(getenv('API_KEY')); | ||
|
||
foreach ($carriers as $carrierOptions) { | ||
$carrierId = $carrierOptions->getCarrierId(); | ||
if (5 !== $carrierId) { | ||
continue; | ||
} | ||
$result = $carrierConfigurationService->getCarrierConfigurations($shop->getId(), $carrierId); | ||
break; | ||
} | ||
|
||
if (! isset($result)) { | ||
throw new \Exception('carrier with carrier id 5 must be present to assert'); | ||
} | ||
|
||
self::assertNotEmpty($result->getDefaultDropOffPointExternalIdentifier()); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Sdk\src\Services; | ||
|
||
use MyParcelNL\Sdk\src\Model\Account\Shop; | ||
use MyParcelNL\Sdk\src\Services\Web\AccountWebService; | ||
use MyParcelNL\Sdk\src\Services\Web\CarrierOptionsWebService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class CarrierOptionsServiceTest extends TestCase | ||
{ | ||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
*/ | ||
public function testGetAccounts(): void | ||
{ | ||
$accountService = (new AccountWebService())->setApiKey(getenv('API_KEY')); | ||
$carrierOptionsService = (new CarrierOptionsWebService())->setApiKey(getenv('API_KEY')); | ||
|
||
$accountService->getAccount() | ||
->getShops() | ||
->first(static function (Shop $shop) use ($carrierOptionsService) { | ||
$result = $carrierOptionsService->getCarrierOptions($shop->getId()); | ||
|
||
self::assertEquals('MyParcelNL\Sdk\src\Model\Account\CarrierOptions', get_class($result->first())); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MyParcelNL\Sdk\Tests\Services; | ||
|
||
use MyParcelNL\Sdk\src\Exception\ApiException; | ||
use MyParcelNL\Sdk\src\Services\Web\RedJePakketjeDropOffPointWebService; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RedJePakketjeDropOffPointServiceTest extends TestCase | ||
{ | ||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
*/ | ||
public function testGetDropOffPoints(): void | ||
{ | ||
$service = (new RedJePakketjeDropOffPointWebService())->setApiKey(getenv('API_KEY')); | ||
$result = $service->getDropOffPoints('6825ME'); | ||
|
||
self::assertNotEmpty($result); | ||
} | ||
|
||
/** | ||
* @throws \MyParcelNL\Sdk\src\Exception\ApiException | ||
* @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException | ||
* @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException | ||
* @throws \Exception | ||
*/ | ||
public function testGetDropOffPoint(): void | ||
{ | ||
$service = (new RedJePakketjeDropOffPointWebService())->setApiKey(getenv('API_KEY')); | ||
$result = $service->getDropOffPoint('e02158ab-7307-434b-956c-0aeb60ef1046'); | ||
|
||
if ($result) { | ||
self::assertEquals('e02158ab-7307-434b-956c-0aeb60ef1046', $result->getLocationCode()); | ||
} else { | ||
Throw new \Exception('Not one drop off point returned for external identifier'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Validator; | ||
|
||
use MyParcelNL\Sdk\src\Exception\ValidationException; | ||
use MyParcelNL\Sdk\src\Rule\Rule; | ||
use MyParcelNL\Sdk\src\Validator\AbstractValidator; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TestRule extends Rule | ||
{ | ||
/** | ||
* @param bool $validationSubject | ||
*/ | ||
public function validate($validationSubject): void | ||
{ | ||
if ($validationSubject) { | ||
$this->addError('Error'); | ||
} | ||
} | ||
} | ||
|
||
class AbstractValidatorTest extends TestCase | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function provideValidatorData(): array | ||
{ | ||
return [ | ||
[ | ||
[ | ||
new TestRule(), | ||
new TestRule(), | ||
new TestRule(), | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param array $rules | ||
* | ||
* @throws \Exception | ||
* @dataProvider provideValidatorData | ||
*/ | ||
public function testValidator(array $rules): void | ||
{ | ||
$testValidator = $this->createAbstractValidator(); | ||
$testValidator::$staticRules = $rules; | ||
|
||
(new $testValidator()) | ||
->validateAll(false) | ||
->report(); | ||
// Expecting no error to be thrown | ||
|
||
try { | ||
(new $testValidator()) | ||
->validateAll(true) | ||
->report(); | ||
} catch (ValidationException $e) { | ||
self::assertSame(['Error', 'Error', 'Error'], $e->getErrors()); | ||
$this->addToAssertionCount(1); | ||
} | ||
|
||
// Make sure the catch assertion has been executed. | ||
self::assertEquals(1, $this->getNumAssertions()); | ||
} | ||
|
||
/** | ||
* @return \MyParcelNL\Sdk\src\Validator\AbstractValidator | ||
*/ | ||
protected function createAbstractValidator() | ||
{ | ||
return new class extends AbstractValidator { | ||
/** | ||
* @see https://stackoverflow.com/a/49038436/10225966 | ||
* @var \MyParcelNL\Sdk\src\Rule\Rule[] | ||
*/ | ||
public static $staticRules; | ||
|
||
/** | ||
* @return \MyParcelNL\Sdk\src\Rule\Rule[] | ||
*/ | ||
protected function getRules(): array | ||
{ | ||
return self::$staticRules; | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.