Skip to content

Commit

Permalink
MM-40: Test and fix import order functionality (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandr-parkhomenko authored and 24198 committed Aug 12, 2020
1 parent 741e626 commit ea13d64
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
marello:
order:
shipping_method.label: Shipping Method
locale_id.label: Locale ID
previous_shipping_method.label: Previously selected Shipping Method
possible_shipping_methods.no_method: No shipping methods are available
possible_shipping_methods.confirmation.title: Review Shipping Cost
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ marello:
sales_channel.label: Sales Channel
sales_channel_name.label: Sales Channel
order_reference.label: Order Reference
locale_id.label: Locale ID
localization.label: Localization
workflow_item.label: Workflow Item
workflow_step.label: Workflow Step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private function entityGetFieldValues($entity, $fields)
*/
protected function isAllRequiredFieldsHasValue(array $values): bool
{
$requiredFields = [self::PRODUCT_FIELD, self::SALES_CHANNEL_FIELD, self::PRODUCT_FIELD];
$requiredFields = [self::PRODUCT_FIELD, self::SALES_CHANNEL_FIELD, self::SALES_CHANNEL_FIELD];
foreach ($requiredFields as $requiredField) {
if (!\array_key_exists($requiredField, $values)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

namespace Marello\Bundle\PaymentBundle\Method\Provider;

class CompositePaymentMethodProvider implements PaymentMethodProviderInterface
use Marello\Bundle\PaymentBundle\Method\RemotePaymentMethod;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;

class CompositePaymentMethodProvider implements PaymentMethodProviderInterface, LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var PaymentMethodProviderInterface[]
*/
Expand Down Expand Up @@ -40,8 +46,15 @@ public function getPaymentMethod($identifier)
return $provider->getPaymentMethod($identifier);
}
}

throw new \InvalidArgumentException('There is no payment method for "' . $identifier . '" identifier');

$this->logger->warning(
'There is no payment method found for given identifier.',
[
'identifier' => $identifier
]
);

return new RemotePaymentMethod($identifier);
}

/**
Expand Down
67 changes: 67 additions & 0 deletions src/Marello/Bundle/PaymentBundle/Method/RemotePaymentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace Marello\Bundle\PaymentBundle\Method;

use Symfony\Component\Form\Extension\Core\Type\HiddenType;

class RemotePaymentMethod implements PaymentMethodInterface
{
/** @var string */
protected $identifier;

/**
* @param string $identifier
*/
public function __construct(string $identifier)
{
$this->identifier = $identifier;
}

/**
* {@inheritDoc}
*/
public function isEnabled()
{
return false;
}

/**
* {@inheritDoc}
*/
public function getIdentifier()
{
return $this->identifier;
}

/**
* {@inheritDoc}
*/
public function getLabel()
{
return $this->identifier;
}

/**
* {@inheritDoc}
*/
public function getOptionsConfigurationFormType()
{
return HiddenType::class;
}

/**
* {@inheritDoc}
*/
public function getSortOrder()
{
return 0;
}

/**
* {@inheritDoc}
*/
public function getOptions()
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ services:
marello_payment.payment_method.composite_provider:
class: 'Marello\Bundle\PaymentBundle\Method\Provider\CompositePaymentMethodProvider'
public: true
calls:
- ['setLogger', ['@logger']]

marello_payment.context.doctrine_line_item_collection_factory:
class: 'Marello\Bundle\PaymentBundle\Context\LineItem\Collection\Doctrine\Factory\DoctrinePaymentLineItemCollectionFactory'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ protected function setUp()
{
$this->paymentMethodProvider = new CompositePaymentMethodProvider();

$this->provider = $this->getMockBuilder(PaymentMethodProviderInterface::class)
->disableOriginalConstructor()
->getMock();
$this->provider = $this->createMock(PaymentMethodProviderInterface::class);
}

public function testGetMethods()
Expand Down Expand Up @@ -59,13 +57,4 @@ public function testRegistry()
$this->assertEquals($method, $this->paymentMethodProvider->getPaymentMethod('test_name'));
$this->assertEquals(['test_name' => $method], $this->paymentMethodProvider->getPaymentMethods());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage There is no payment method for "wrong_name" identifier
*/
public function testRegistryWrongMethod()
{
$this->paymentMethodProvider->getPaymentMethod('wrong_name');
}
}

0 comments on commit ea13d64

Please sign in to comment.