Skip to content

Commit

Permalink
Merge pull request #24 from myparcelnl/release-branche
Browse files Browse the repository at this point in the history
Release branche
  • Loading branch information
Reindert authored Sep 20, 2017
2 parents d40dd4e + 18889f1 commit 1fef835
Show file tree
Hide file tree
Showing 17 changed files with 556 additions and 115 deletions.
89 changes: 89 additions & 0 deletions Tests/ReturnLabelTest/SendReturnLabelMailTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php
/**
* A test to send a return email
*
* LICENSE: This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*
* If you want to add improvements, please create a fork in our GitHub:
* https://github.com/myparcelnl/magento
*
* @author Reindert Vetter <[email protected]>
* @copyright 2010-2017 MyParcel
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL
* @link https://github.com/myparcelnl/magento
* @since File available since Release 2.0.0
*/

namespace MyParcelNL\Sdk\Tests\ReturnLabelTest;

use MyParcelNL\Sdk\src\Helper\MyParcelCollection;
use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository;

class SendReturnLabelMailTest extends \PHPUnit_Framework_TestCase
{
public function testSendReturnLabelMail()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

$myParcelCollection = $this->getCollectionWithParentConsignment();
$myParcelCollection->sendReturnLabelMails();

$this->assertNotNull($myParcelCollection);
}

/**
* @return MyParcelCollection
*/
private function getCollectionWithParentConsignment()
{
$consignmentTest = $this->additionProviderNewConsignment();

$myParcelCollection = new MyParcelCollection();

$consignment = (new MyParcelConsignmentRepository())
->setApiKey($consignmentTest['api_key'])
->setCountry($consignmentTest['cc'])
->setPerson($consignmentTest['person'])
->setCompany($consignmentTest['company'])
->setFullStreet($consignmentTest['full_street_test'])
->setPostalCode($consignmentTest['postal_code'])
->setCity($consignmentTest['city'])
->setEmail($consignmentTest['email'])
->setPhone($consignmentTest['phone']);

$myParcelCollection
->addConsignment($consignment)
->setLinkOfLabels()
->setLatestData();

return $myParcelCollection;
}

/**
* Data for the test
*
* @return array
*/
private function additionProviderNewConsignment()
{
return [
'api_key' => getenv('API_KEY'),
'cc' => 'NL',
'person' => 'Piet',
'email' => '[email protected]',
'company' => 'Mega Store',
'full_street_test' => 'Koestraat 55',
'number_suffix' => '',
'postal_code' => '2231JE',
'city' => 'Katwijk',
'phone' => '123-45-235-435',
'label_description' => 'Label description',

];
}
}
2 changes: 1 addition & 1 deletion Tests/SendConsignments/SendMailboxConsignmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SendMailboxConsignmentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SendConsignments/SendMorningShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SendMorningShipmentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testSendOneConsignment()
ini_set('display_errors', 1);

if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SendConsignments/SendNightShipmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SendNightShipmentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/SendConsignments/SendOneConsignmentTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Create one concept
* Create one consignment
*
* If you want to add improvements, please create a fork in our GitHub:
* https://github.com/myparcelnl
Expand Down Expand Up @@ -32,7 +32,7 @@ class SendOneConsignmentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SendOneConsignmentWithoutEmailTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
152 changes: 152 additions & 0 deletions Tests/SendConsignments/SendOneInternationalConsignmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

/**
* Create international consignment
*
* If you want to add improvements, please create a fork in our GitHub:
* https://github.com/myparcelnl
*
* @author Reindert Vetter <[email protected]>
* @copyright 2010-2017 MyParcel
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL
* @link https://github.com/myparcelnl/sdk
* @since File available since Release v0.1.0
*/

namespace MyParcelNL\Sdk\tests\SendConsignments\SendOneInternationalConsignmentTest;

use MyParcelNL\Sdk\src\Helper\MyParcelCollection;
use MyParcelNL\Sdk\src\Model\MyParcelCustomsItem;
use MyParcelNL\Sdk\src\Model\Repository\MyParcelConsignmentRepository;


/**
* Class SendOneInternationalConsignmentTest
* @package MyParcelNL\Sdk\tests\SendOneConsignmentTest
*/
class SendOneInternationalConsignmentTest extends \PHPUnit_Framework_TestCase
{

/**
* Test one shipment with createConcepts()
*/
public function testSendOneConsignment()
{
error_reporting(E_ALL);
ini_set('display_errors', 1);
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

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

$myParcelCollection = new MyParcelCollection();

$consignment = (new MyParcelConsignmentRepository())
->setApiKey($consignmentTest['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']);

if (key_exists('package_type', $consignmentTest)) {
$consignment->setPackageType($consignmentTest['package_type']);
}

if (key_exists('large_format', $consignmentTest)) {
$consignment->setLargeFormat($consignmentTest['large_format']);
}

if (key_exists('only_recipient', $consignmentTest)) {
$consignment->setOnlyRecipient($consignmentTest['only_recipient']);
}

if (key_exists('signature', $consignmentTest)) {
$consignment->setSignature($consignmentTest['signature']);
}

if (key_exists('return', $consignmentTest)) {
$consignment->setReturn($consignmentTest['return']);
}

if (key_exists('insurance', $consignmentTest)) {
$consignment->setInsurance($consignmentTest['insurance']);
}

if (key_exists('label_description', $consignmentTest)) {
$consignment->setLabelDescription($consignmentTest['label_description']);
}

// Add items for international shipments
foreach ($consignmentTest['custom_items'] as $customItem) {
$item = (new MyParcelCustomsItem())
->setDescription($customItem['description'])
->setAmount($customItem['amount'])
->setWeight($customItem['weight'])
->setItemValue($customItem['item_value'])
->setClassification($customItem['classification'])
->setCountry($customItem['country']);

$consignment->addItem($item);
}

$myParcelCollection
->addConsignment($consignment)
->setLinkOfLabels();

$this->assertEquals(true, preg_match("#^https://api.myparcel.nl/pdfs#", $myParcelCollection->getLinkOfLabels()), 'Can\'t get link of PDF');

echo "\033[32mGenerated international shipment label: \033[0m";
print_r($myParcelCollection->getLinkOfLabels());
echo "\n\033[0m";

/** @var MyParcelConsignmentRepository $consignment */
$consignment = $myParcelCollection->getOneConsignment();
$this->assertEquals(true, preg_match("#^CV#", $consignment->getBarcode()), 'Barcode is not set');

/** @todo; clear consignment in MyParcelCollection */
}
}

/**
* Data for the test
*
* @return array
*/
public function additionProvider()
{
return [
[
'api_key' => getenv('API_KEY'),
'cc' => 'CA',
'person' => 'Reindert',
'company' => 'Big Sale BV',
'full_street_test' => 'Plein 1940-45 3b',
'full_street' => 'Plein 1940-45 3 b',
'street' => 'Plein 1940-45',
'number' => 3,
'number_suffix' => 'b',
'postal_code' => '2231JE',
'city' => 'Rijnsburg',
'phone' => '123456',
'package_type' => 1,
'label_description' => 112345,
'custom_items' => [
[
'description' => 'Cool Mobile',
'amount' => 2,
'weight' => 2000,
'item_value' => 40000,
'classification' => 2008,
'country' => 'DU',
]
],
],
];
}
}
2 changes: 1 addition & 1 deletion Tests/SendConsignments/SendPickupFromCheckoutDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SendPickupFromCheckoutDataTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SendReferenceIdentifierConsignmentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SendConsignments/SendUserAgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SendUserAgentTest extends \PHPUnit_Framework_TestCase
public function testSendOneConsignment()
{
if (getenv('API_KEY') == null) {
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31\n\033[0m. PhpStorm example: http://take.ms/sgpgU5";
echo "\033[31m Set MyParcel API-key in 'Environment variables' before running UnitTest. Example: API_KEY=f8912fb260639db3b1ceaef2730a4b0643ff0c31. PhpStorm example: http://take.ms/sgpgU5\n\033[0m";
return $this;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myparcelnl/sdk",
"version": "v1.1.10",
"version": "v1.2.0",
"description": "This package is designed to send and receive data from MyParcel by means of an API.",
"homepage": "https://www.myparcel.nl",
"tags": ["MyParcel", "My Parcel", "Post NL", "PostNL"],
Expand Down
Loading

0 comments on commit 1fef835

Please sign in to comment.