Skip to content

Commit

Permalink
Merge pull request #94 from Paazl/release/1.12.0
Browse files Browse the repository at this point in the history
Release/1.12.0
  • Loading branch information
Marvin-Magmodules authored Jun 16, 2022
2 parents 1c12ef5 + 30a4b73 commit a75277c
Show file tree
Hide file tree
Showing 16 changed files with 340 additions and 67 deletions.
51 changes: 26 additions & 25 deletions .github/workflows/setup-di-compile.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
name: setup:di:compile
name: Run setup:upgrade and setup:di:compile
on: [pull_request]

jobs:
build:
strategy:
matrix:
include:
- PHP_VERSION: php72-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.6-p1
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
build:
strategy:
matrix:
include:
- PHP_VERSION: php71-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.7
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.3-with-replacements
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.4
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Start Docker
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}
- name: Start Docker
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker-compose -f .github/workflows/templates/docker-compose.yml up -d

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json
- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload our code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/
- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require paazl/magento2-checkout-widget:dev-continuous-integration-test-branch

- name: Install the extension in Magento
run: docker exec magento-project-community-edition composer require paazl/magento2-checkout-widget:dev-continuous-integration-test-branch

- name: Run setup:di:compile
run: docker exec magento-project-community-edition php bin/magento setup:di:compile
- name: Activate the extension and run setup:upgrade and setup:di:compile
run: docker exec magento-project-community-edition bash -c "php bin/magento module:enable Paazl_CheckoutWidget && php bin/magento setup:upgrade && php bin/magento setup:di:compile"
35 changes: 23 additions & 12 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
name: Unit Tests

on: pull_request
on: [pull_request]

jobs:
build:
strategy:
matrix:
PHP_VERSION: [php71-fpm, php72-fpm]
MAGENTO_VERSION: [2.2.11, 2.3.4]
exclude:
- PHP_VERSION: php72-fpm
MAGENTO_VERSION: 2.2.11
include:
- PHP_VERSION: php71-fpm
MAGENTO_VERSION: 2.3.3
- PHP_VERSION: php73-fpm
MAGENTO_VERSION: 2.3.7
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.3-with-replacements
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.4
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2

- name: Start Docker
run: PHP_VERSION=${{ matrix.PHP_VERSION }} MAGENTO_VERSION=magento${{ matrix.MAGENTO_VERSION }} docker-compose -f .github/workflows/templates/docker-compose.yml up -d
run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }}

- name: Create branch for Composer and remove version from composer.json
run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json

- name: Upload the code into the docker container
run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ && docker exec magento-project-community-edition composer require paazl/magento2-checkout-widget:dev-continuous-integration-test-branch

- name: Upload our code into the docker container
run: docker cp $(pwd)/. magento-project-community-edition:/data/extensions/workdir && docker exec magento-project-community-edition composer require paazl/magento2-checkout-widget:@dev
- name: Activate the extension and run setup:upgrade
run: docker exec magento-project-community-edition bash -c "php bin/magento module:enable Paazl_CheckoutWidget && php bin/magento setup:upgrade"

- name: Run tests
run: docker exec magento-project-community-edition bash -c "vendor/bin/phpunit extensions/workdir/Test/Unit"
run: docker exec magento-project-community-edition bash -c "vendor/bin/phpunit extensions/*/Test/Unit"
18 changes: 18 additions & 0 deletions GraphQL/Replaces/ResolverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/*
* Copyright © Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Framework\GraphQl\Query;

/**
* This class is available in default Magento 2.3.3 versions and higher. But due to Composer replace techniques, this
* class is sometimes missing. So check if it's available, and if not, create an empty variant. It's then only used
* for class generation in the setup:di:compile process.
*/
if (!interface_exists(ResolverInterface::class)) {
interface ResolverInterface
{
}
}
69 changes: 69 additions & 0 deletions GraphQL/Resolver/ConfigurationResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/*
* Copyright © Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\GraphQL\Resolver;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
use Magento\Framework\GraphQl\Query\ResolverInterface;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\QuoteIdMaskFactory;
use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResource;
use Paazl\CheckoutWidget\Model\Checkout\WidgetConfigProvider;

class ConfigurationResolver implements ResolverInterface
{
/**
* @var WidgetConfigProvider
*/
private $widgetConfigProvider;

/**
* @var CartRepositoryInterface
*/
private $cartRepository;

/**
* @var QuoteIdMaskFactory
*/
private $quoteIdMaskFactory;

/**
* @var QuoteIdMaskResource
*/
private $quoteIdMaskResource;

public function __construct(
WidgetConfigProvider $widgetConfigProvider,
CartRepositoryInterface $cartRepository,
QuoteIdMaskFactory $quoteIdMaskFactory,
QuoteIdMaskResource $quoteIdMaskResource
) {
$this->widgetConfigProvider = $widgetConfigProvider;
$this->cartRepository = $cartRepository;
$this->quoteIdMaskFactory = $quoteIdMaskFactory;
$this->quoteIdMaskResource = $quoteIdMaskResource;
}

public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if (!isset($args['cart_id']) || empty($args['cart_id'])) {
throw new GraphQlInputException(__('"cart_id" is required'));
}

$quoteIdMask = $this->quoteIdMaskFactory->create();
$this->quoteIdMaskResource->load($quoteIdMask, $args['cart_id'], 'masked_id');

/** @var CartInterface|Quote $cart */
$cart = $this->cartRepository->get($quoteIdMask->getQuoteId());

$this->widgetConfigProvider->setQuote($cart);
return $this->widgetConfigProvider->getConfig();
}
}
6 changes: 3 additions & 3 deletions Model/Api/Builder/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public function parseAddress(Address $shippingAddress)
}

return [
'street' => trim($matches['street'] ?? null),
'houseNumber' => trim($matches['houseNumber'] ?? null),
'houseNumberExtension' => trim($matches['houseNumberExtension'] ?? null),
'street' => trim($matches['street'] ?? ''),
'houseNumber' => trim($matches['houseNumber'] ?? ''),
'houseNumberExtension' => trim($matches['houseNumberExtension'] ?? ''),
];
}

Expand Down
44 changes: 43 additions & 1 deletion Model/Carrier/Paazlshipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Magento\Quote\Model\Quote\Address\RateResult\MethodFactory;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Paazl\CheckoutWidget\Logger\PaazlLogger;
use Paazl\CheckoutWidget\Model\Api\Converter\ShippingOptions;
use Paazl\CheckoutWidget\Model\Api\PaazlApiFactory;
use Paazl\CheckoutWidget\Model\Checkout\WidgetConfigProvider;
use Paazl\CheckoutWidget\Model\ExtInfoHandler;
use Paazl\CheckoutWidget\Model\Config;
use Magento\Framework\App\State as AppState;
Expand Down Expand Up @@ -85,6 +88,21 @@ class Paazlshipping extends AbstractCarrier implements CarrierInterface
*/
private $tokenRetriever;

/**
* @var PaazlApiFactory
*/
private $apiFactory;

/**
* @var ShippingOptions
*/
private $shippingOptionsConverter;

/**
* @var WidgetConfigProvider
*/
private $configProvider;

/**
* Paazlshipping constructor.
*
Expand All @@ -111,12 +129,17 @@ public function __construct(
ExtInfoHandler $extInfoHandler,
TokenRetriever $tokenRetriever,
PaazlLogger $paazlLogger,
PaazlApiFactory $apiFactory,
ShippingOptions $shippingOptionsConverter,
WidgetConfigProvider $configProvider,
array $data = []
) {
$this->rateResultFactory = $rateResultFactory;
$this->rateMethodFactory = $rateMethodFactory;
$this->logger = $paazlLogger;

$this->apiFactory = $apiFactory;
$this->shippingOptionsConverter = $shippingOptionsConverter;
$this->configProvider = $configProvider;
parent::__construct($scopeConfig, $rateErrorFactory, $logger, $data);
$this->extInfoHandler = $extInfoHandler;
$this->config = $config;
Expand Down Expand Up @@ -190,6 +213,25 @@ public function collectRates(RateRequest $request)
}

try {
$countryId = $quote->getShippingAddress()->getCountryId() ?
$quote->getShippingAddress()->getCountryId() :
$this->configProvider->getDefaultCountry();
$postcode = $quote->getShippingAddress()->getPostcode() ?
$quote->getShippingAddress()->getPostcode() :
$this->configProvider->getDefaultPostcode();
if ($countryId && $postcode) {
$api = $this->apiFactory->create($quote->getStoreId());
$config = $this->configProvider->setQuote($quote)->getConfig();
$shippingOptions = $this->shippingOptionsConverter->convert(
$api->getShippingOptions($config)
);
if (isset($shippingOptions['shippingOptions'][0])) {
$firstOption = $shippingOptions['shippingOptions'][0];
$shippingPrice = $firstOption['rate'];
$method->setMethodTitle($firstOption['name']);
}
}

$this->tokenRetriever->retrieveByQuote($quote);

$info = $this->extInfoHandler->getInfoFromQuote($quote);
Expand Down
File renamed without changes.
14 changes: 3 additions & 11 deletions Test/Unit/Model/Api/Builder/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@
use Paazl\CheckoutWidget\Model\Handler\Item;
use Paazl\CheckoutWidget\Model\ResourceModel\Order\OrderReferenceRepository;
use Paazl\CheckoutWidget\Model\ShippingInfo;
use Paazl\CheckoutWidget\Test\Unit\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class OrderTest extends TestCase
class OrderTest extends UnitTestCase
{

/**
* @var ObjectManagerHelper
*/
private $objectManager;

/**
* @var Order
*/
Expand All @@ -49,10 +43,8 @@ class OrderTest extends TestCase
*/
private $configMock;

protected function setUp()
protected function setUpWithoutVoid()
{
$this->objectManager = (new ObjectManagerHelper($this));

$extInfoHandlerMock = $this->getMockBuilder(ExtInfoHandler::class)->disableOriginalConstructor()->getMock();
$this->extInfoHandlerMock = $extInfoHandlerMock;

Expand Down
15 changes: 3 additions & 12 deletions Test/Unit/Model/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,25 @@
namespace Paazl\CheckoutWidget\Test\Unit\Model;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Paazl\CheckoutWidget\Model\Config;
use Paazl\CheckoutWidget\Test\Unit\UnitTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ConfigTest extends TestCase
class ConfigTest extends UnitTestCase
{

/**
* @var object
*/
private $entity;

/**
* @var ObjectManagerHelper
*/
private $objectManager;

/**
* @var ScopeConfigInterface|MockObject
*/
private $scopeConfigMock;

protected function setUp()
protected function setUpWithoutVoid()
{
/** @var ObjectManagerHelper objectManager */
$this->objectManager = (new ObjectManagerHelper($this));

/** @var ScopeConfigInterface|MockObject $scopeConfigMock */
$scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->scopeConfigMock = $scopeConfigMock;
Expand Down
31 changes: 31 additions & 0 deletions Test/Unit/PHPUnit/UnitTestCaseVersion8AndLower.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
// phpcs:disable Generic.Classes.DuplicateClassName.Found
/**
* Copyright © Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\Test\Unit;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;

class UnitTestCase extends TestCase
{
/**
* @var ObjectManager
*/
protected $objectManager;

protected function setUp()
{
parent::setUp();

$this->objectManager = new ObjectManager($this);
$this->setUpWithoutVoid();
}

protected function setUpWithoutVoid()
{
}
}
Loading

0 comments on commit a75277c

Please sign in to comment.