Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:tig-nl/tig-extension-tig-postnl-…
Browse files Browse the repository at this point in the history
…magento2
  • Loading branch information
tig-dennisvanderhammen committed Apr 8, 2019
2 parents bc880dd + d2317ef commit a60b631
Show file tree
Hide file tree
Showing 24 changed files with 390 additions and 270 deletions.
53 changes: 15 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,30 @@ addons:

language: php

php: 7.0

env:
global:
- CODE_COVERAGE=false
- DI_COMPILE=true

# We have decided to only test the latest two of each major releases.
matrix:
# - MAGENTO_VERSION=2.1.0
# - MAGENTO_VERSION=2.1.1
# - MAGENTO_VERSION=2.1.2
# - MAGENTO_VERSION=2.1.3
# - MAGENTO_VERSION=2.1.4
# - MAGENTO_VERSION=2.1.5
# - MAGENTO_VERSION=2.1.6
# - MAGENTO_VERSION=2.1.7
# - MAGENTO_VERSION=2.1.8
# - MAGENTO_VERSION=2.1.9
# - MAGENTO_VERSION=2.1.10
# - MAGENTO_VERSION=2.1.11
# - MAGENTO_VERSION=2.1.12
# - MAGENTO_VERSION=2.1.13
# - MAGENTO_VERSION=2.1.14
- MAGENTO_VERSION=2.1.15
- MAGENTO_VERSION=2.1.16
# - MAGENTO_VERSION=2.2.0
# - MAGENTO_VERSION=2.2.1
# - MAGENTO_VERSION=2.2.2
# - MAGENTO_VERSION=2.2.3
# - MAGENTO_VERSION=2.2.4
# - MAGENTO_VERSION=2.2.5
- MAGENTO_VERSION=2.2.6
# - MAGENTO_VERSION=2.2.7
- DI_COMPILE=false

matrix:
# PHP 7.1 would be supported in Magento since Magento 2.2
# And there wouldn't be support of PHP 7.1 in Magento 2.0 or 2.1
# PHP 7 is only supported in Magento 2.0.x and 2.1.x
# PHP 7.1 is only supported in Magento 2.2.x
# PHP 7.2 is only supported in Magento 2.3.x
include:
- php: 7.1
- php: 7.0
env: MAGENTO_VERSION=2.1.16
- php: 7.0
env: MAGENTO_VERSION=2.1.17
- php: 7.0
env: MAGENTO_VERSION=2.2.7
- php: 7.2
- php: 7.1
env: MAGENTO_VERSION=2.2.8
- php: 7.1
env: MAGENTO_VERSION=2.3.0
- php: 7.1
env: MAGENTO_VERSION=2.3.0 DI_COMPILE=false
env: MAGENTO_VERSION=2.3.1 # DI_COMPILE=true
- php: 7.2
env: MAGENTO_VERSION=2.3.0 CODE_COVERAGE=true
env: MAGENTO_VERSION=2.3.1 CODE_COVERAGE=true

before_script:
- export PATH=$PATH:$HOME/.composer/vendor/bin
Expand All @@ -64,7 +41,7 @@ before_script:
- bash Test/Script/Setup.sh

script:
- if [ "$CODE_COVERAGE" = "false" && "$DI_COMPILE" = "true"]; then php /tmp/magento2/bin/magento setup:di:compile; fi # Check for compilation errors
- if [ $CODE_COVERAGE == false ] && [ $DI_COMPILE == true ]; then php /tmp/magento2/bin/magento setup:di:compile; fi # Check for compilation errors
- grunt phpcs
- grunt lint
- grunt exec:phraseTest
Expand Down
2 changes: 1 addition & 1 deletion Block/Adminhtml/Config/Support/SupportTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

class SupportTab extends Template implements RendererInterface
{
const POSTNL_VERSION = '1.7.4-RC1';
const POSTNL_VERSION = '1.7.4';

const XPATH_SUPPORTED_MAGENTO_VERSION = 'tig_postnl/supported_magento_version';

Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ module.exports = function (grunt) {

integrationTests:
'cd ' + magento2path + 'dev/tests/integration &&' +
'php -ddisplay_errors=1 ../../../vendor/phpunit/phpunit/phpunit --testsuite "TIG PostNL Integration Tests"',
'php -ddisplay_errors=1 ../../../vendor/phpunit/phpunit/phpunit --testsuite "TIG PostNL Tests"',

ciTests:
'cd ' + magento2path + 'dev/tests/integration &&' +
Expand Down
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function getEndDate($startDate)
*/
$maximumNumberOfDeliveryDays = $this->shippingOptions->getMaxAmountOfDeliverydays() - 1;

$endDate = $this->dateTime->date($startDate);
$endDate = $this->dateTime->date($startDate, 'nl_NL');
// @codingStandardsIgnoreLine
$endDate->add(new \DateInterval("P{$maximumNumberOfDeliveryDays}D"));

Expand Down
21 changes: 15 additions & 6 deletions Observer/TIGPostNLOrderSaveBefore/SetDefaultData.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ private function getOptionFromQuote()
*/
private function checkByAddressData(OrderInterface $order)
{
$address = null;
$country = null;

/** @noinspection PhpUndefinedMethodInspection */
Expand All @@ -209,14 +208,24 @@ private function checkByAddressData(OrderInterface $order)
return $address;
}

if (!$address && $order->getOrderId()) {
$address = $this->magentoOrder->getShippingAddress($order->getOrderId());
/**
* Added try-catch wrapper to prevent 500-error in \Magento\Sales\Model\OrderRepository::get()
* which occurred since Magento 2.2.8/2.3.1.
*/
try {
if ($order->getOrderId()) {
return $this->magentoOrder->getShippingAddress($order->getOrderId());
}
} catch (\Error $e) {
if ($order->getQuoteId()) {
return $address = $this->magentoOrder->getShippingAddress($order->getQuoteId(), 'quote');
}
}

if (!$address && $order->getQuoteId()) {
$address = $this->magentoOrder->getShippingAddress($order->getQuoteId(), 'quote');
if ($order->getQuoteId()) {
return $this->magentoOrder->getShippingAddress($order->getQuoteId(), 'quote');
}

return $address;
return null;
}
}
5 changes: 4 additions & 1 deletion Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
if (version_compare($context->getVersion(), '1.6.1', '<')) {
$this->upgradeSchemas($this->upgradeSchemaObjects['v1.6.1'], $setup, $context);
}


if (version_compare($context->getVersion(), '1.7.4', '<')) {
$this->upgradeSchemas($this->upgradeSchemaObjects['v1.7.4'], $setup, $context);
}

$setup->endSetup();
}
Expand Down
86 changes: 86 additions & 0 deletions Setup/V174/Schema/InstallDownpartnerAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php
/**
*
* ..::..
* ..::::::::::::..
* ::'''''':''::'''''::
* ::.. ..: : ....::
* :::: ::: : : ::
* :::: ::: : ''' ::
* ::::..:::..::.....::
* ''::::::::::::''
* ''::''
*
*
* NOTICE OF 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 are unable to obtain it through the world-wide-web, please send an email
* to servicedesk@tig.nl so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future. If you wish to customize this module for your
* needs please contact servicedesk@tig.nl for more information.
*
* @copyright Copyright (c) Total Internet Group B.V. https://tig.nl/copyright
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*/

namespace TIG\PostNL\Setup\V174\Schema;

use \TIG\PostNL\Setup\AbstractColumnsInstaller;

class InstallDownpartnerAttributes extends AbstractColumnsInstaller
{
const TABLE_NAME = 'tig_postnl_shipment';

// @codingStandardsIgnoreLine
protected $columns = [
'downpartner_id',
'downpartner_location',
'downpartner_barcode',
];

public function installDownpartnerIdColumn()
{
return [
// @codingStandardsIgnoreLine
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 32,
'nullable' => true,
'default' => null,
'comment' => 'Downpartner ID',
'after' => 'confirmed'
];
}

public function installDownpartnerLocationColumn()
{
return [
// @codingStandardsIgnoreLine
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 16,
'nullable' => true,
'default' => null,
'comment' => 'Downpartner Location',
'after' => 'downpartner_id'
];
}

public function installDownpartnerBarcodeColumn()
{
return [
// @codingStandardsIgnoreLine
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 32,
'nullable' => true,
'default' => null,
'comment' => 'Downpartner Barcode',
'after' => 'downpartner_location'
];
}
}
21 changes: 11 additions & 10 deletions Test/Fixtures/install-config-mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*/
return [
'db-host' => 'MAGENTO_DB_HOST',
'db-user' => 'MAGENTO_DB_USER',
'db-password' => 'MAGENTO_DB_PASS',
'db-name' => 'MAGENTO_DB_NAME',
'db-prefix' => '',
'db-host' => 'MAGENTO_DB_HOST',
'db-user' => 'MAGENTO_DB_USER',
'db-password' => 'MAGENTO_DB_PASS',
'db-name' => 'MAGENTO_DB_NAME',
'db-prefix' => '',
'key' => 'ef0e78a6c44764690780138ce89b7791',
'backend-frontname' => 'admin',
'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL,
'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME,
'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME,
'admin-user' => \Magento\TestFramework\Bootstrap::ADMIN_NAME,
'admin-password' => \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD,
'admin-email' => \Magento\TestFramework\Bootstrap::ADMIN_EMAIL,
'admin-firstname' => \Magento\TestFramework\Bootstrap::ADMIN_FIRSTNAME,
'admin-lastname' => \Magento\TestFramework\Bootstrap::ADMIN_LASTNAME,
];
2 changes: 1 addition & 1 deletion Test/Fixtures/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
>
<!-- Test suites definition -->
<testsuites>
<!-- Memory tests run first to prevent influence of other tests on accuracy of memory measurements -->
<testsuite name="TIG PostNL Tests">
<directory>../../../app/code/TIG/PostNL/Test</directory>
<directory>../../../vendor/tig/postnl/Test</directory>
<exclude>../../../app/code/Magento</exclude>
<exclude>../../../vendor/magento</exclude>
</testsuite>
</testsuites>
<!-- Code coverage filters -->
Expand Down
10 changes: 7 additions & 3 deletions Test/Script/Setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ fi

( cd "${BUILD_DIR}/" && composer config minimum-stability dev )
( cd "${BUILD_DIR}/" && composer config repositories.postnl "${REPOSITORY_CONFIG}" )
sed -i "s/^memory_limit =.*$/memory_limit = 4096M/" $(php -i | grep 'Loaded Configuration File' | sed 's/^.*=> //')
sed -i "s/^memory_limit =.*$/memory_limit = 4096M/" $(php -i | grep 'Additional .ini files parsed' | sed 's/^.*=> //' | tr -d ,)
( cd "${BUILD_DIR}/" && composer require tig/postnl --ignore-platform-reqs )

mysql -u${MAGENTO_DB_USER} ${MYSQLPASS} -h${MAGENTO_DB_HOST} -P${MAGENTO_DB_PORT} -e "DROP DATABASE IF EXISTS \`${MAGENTO_DB_NAME}\`; CREATE DATABASE \`${MAGENTO_DB_NAME}\`;"
mysql -u${MAGENTO_DB_USER} ${MYSQLPASS} -h${MAGENTO_DB_HOST} -P${MAGENTO_DB_PORT} ${MAGENTO_DB_NAME} < Test/Fixtures/tig-postnl-fixture.sql

chmod 777 "${BUILD_DIR}/var/"
chmod 777 "${BUILD_DIR}/pub/"
chmod 777 "${BUILD_DIR}/vendor/phpunit/phpunit/phpunit"
chmod -R 6777 "${BUILD_DIR}/var/"
chmod -R 6777 "${BUILD_DIR}/pub/"
chmod -R 6777 "${BUILD_DIR}/dev/"
if [[ $MAGENTO_VERSION != "2.1"* ]]; then chmod -R 6777 "${BUILD_DIR}/generated/"; fi
chmod -R 6777 "${BUILD_DIR}/vendor/phpunit/phpunit/phpunit"

( cd ${BUILD_DIR} && php -d memory_limit=2048M bin/magento setup:upgrade )
2 changes: 1 addition & 1 deletion Test/Unit/Webservices/SoapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class SoapTest extends TestCase
public function setUp()
{
$this->soapClient = $this->getMock(\Zend\Soap\Client::class);
$this->endpointMock = $this->getMock(\TIG\PostNL\Webservices\AbstractEndpoint::class);
$this->endpointMock = $this->getFakeMock(\TIG\PostNL\Webservices\AbstractEndpoint::class, true);
$this->accountConfiguration = $this->getFakeMock(\TIG\PostNL\Config\Provider\AccountConfiguration::class, true);
$this->defaultConfiguration = $this->getFakeMock(\TIG\PostNL\Config\Provider\DefaultConfiguration::class, true);
$this->exceptionHandler = $this->getFakeMock(\TIG\PostNL\Webservices\ExceptionHandler::class, true);
Expand Down
36 changes: 36 additions & 0 deletions Webservices/AbstractEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,26 @@
*/
namespace TIG\PostNL\Webservices;

use TIG\PostNL\Model\Shipment;
use TIG\PostNL\Api\Data\ShipmentInterface;
use TIG\PostNL\Webservices\Parser\Label\Shipments as ShipmentData;

abstract class AbstractEndpoint
{
/** @var \TIG\PostNL\Webservices\Parser\Label\Shipments $shipmentData */
private $shipmentData;

/**
* AbstractEndpoint constructor.
*
* @param \TIG\PostNL\Webservices\Parser\Label\Shipments $shipmentData
*/
public function __construct(
ShipmentData $shipmentData
) {
$this->shipmentData = $shipmentData;
}

/**
* @throws \Magento\Framework\Webapi\Exception
* @return mixed
Expand All @@ -43,4 +61,22 @@ abstract public function call();
* @return string
*/
abstract public function getLocation();

/**
* @param Shipment|ShipmentInterface $shipment
* @param $currentShipmentNumber
*
* @return array
*/
public function getShipments($shipment, $currentShipmentNumber)
{
$shipments = [];
$parcelCount = $shipment->getParcelCount();

for ($number = $currentShipmentNumber; $number <= $parcelCount; $number++) {
$shipments[] = $this->shipmentData->get($shipment, $number);
}

return ['Shipment' => $shipments];
}
}
Loading

0 comments on commit a60b631

Please sign in to comment.