Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Paypal transparent test class
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class TransparentTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -194,7 +196,7 @@ private function getPaymentExtensionInterfaceFactory()
->disableOriginalConstructor()
->getMock();
$orderPaymentExtension = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
->setMethods(['setVaultPaymentToken'])
->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])
->disableOriginalConstructor()
->getMock();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

/**
* @author Magento Core Team <[email protected]>
*/
namespace Magento\Reports\Model\ResourceModel\Product;

use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;

/**
* Products Report collection.
*
Expand Down Expand Up @@ -90,6 +90,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
* @param \Magento\Catalog\Model\Product\Type $productType
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
* @param ProductLimitationFactory|null $productLimitationFactory
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand Down Expand Up @@ -117,7 +118,8 @@ public function __construct(
\Magento\Reports\Model\Event\TypeFactory $eventTypeFactory,
\Magento\Catalog\Model\Product\Type $productType,
\Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource,
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
ProductLimitationFactory $productLimitationFactory = null
) {
$this->setProductEntityId($product->getEntityIdField());
$this->setProductEntityTableName($product->getEntityTable());
Expand All @@ -142,7 +144,8 @@ public function __construct(
$customerSession,
$dateTime,
$groupManagement,
$connection
$connection,
$productLimitationFactory
);
$this->_eventTypeFactory = $eventTypeFactory;
$this->_productType = $productType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Reports\Test\Unit\Model\ResourceModel\Product;

Expand All @@ -12,6 +13,8 @@
use Magento\Catalog\Model\Product\Type as ProductType;
use Magento\Catalog\Model\ResourceModel\Helper;
use Magento\Catalog\Model\ResourceModel\Product as ResourceProduct;
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation;
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
use Magento\Catalog\Model\ResourceModel\Url;
use Magento\Customer\Api\GroupManagementInterface;
use Magento\Customer\Model\Session;
Expand Down Expand Up @@ -75,6 +78,11 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
*/
private $selectMock;

/**
* SetUp method
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function setUp()
{
$this->objectManager = new ObjectManager($this);
Expand Down Expand Up @@ -138,31 +146,44 @@ protected function setUp()
$this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->connectionMock);
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);

$this->collection = new ProductCollection(
$entityFactoryMock,
$loggerMock,
$fetchStrategyMock,
$eventManagerMock,
$eavConfigMock,
$this->resourceMock,
$eavEntityFactoryMock,
$resourceHelperMock,
$universalFactoryMock,
$storeManagerMock,
$moduleManagerMock,
$productFlatStateMock,
$scopeConfigMock,
$optionFactoryMock,
$catalogUrlMock,
$localeDateMock,
$customerSessionMock,
$dateTimeMock,
$groupManagementMock,
$productMock,
$this->eventTypeFactoryMock,
$productTypeMock,
$quoteResourceMock,
$this->connectionMock
$productLimitationFactoryMock = $this->createPartialMock(
ProductLimitationFactory::class,
['create']
);
$productLimitation = $this->createMock(ProductLimitation::class);
$productLimitationFactoryMock->expects($this->once())
->method('create')
->willReturn($productLimitation);

$this->collection = $this->objectManager->getObject(
ProductCollection::class,
[
'entityFactory' => $entityFactoryMock,
'logger' => $loggerMock,
'fetchStrategy' => $fetchStrategyMock,
'eventManager' => $eventManagerMock,
'eavConfig' => $eavConfigMock,
'resource' => $this->resourceMock,
'eavEntityFactory' => $eavEntityFactoryMock,
'resourceHelper' => $resourceHelperMock,
'universalFactory' => $universalFactoryMock,
'storeManager' => $storeManagerMock,
'moduleManager' => $moduleManagerMock,
'catalogProductFlatState' => $productFlatStateMock,
'scopeConfig' => $scopeConfigMock,
'productOptionFactory' => $optionFactoryMock,
'catalogUrl' => $catalogUrlMock,
'localeDate' => $localeDateMock,
'customerSession' => $customerSessionMock,
'dateTime' => $dateTimeMock,
'groupManagement' => $groupManagementMock,
'product' => $productMock,
'eventTypeFactory' => $this->eventTypeFactoryMock,
'productType' => $productTypeMock,
'quoteResource' => $quoteResourceMock,
'connection' => $this->connectionMock,
'productLimitationFactory' => $productLimitationFactoryMock
]
);
}

Expand Down
57 changes: 39 additions & 18 deletions app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Vault\Test\Unit\Model\Method;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
Expand All @@ -25,6 +27,7 @@

/**
* Class VaultTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class VaultTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -140,7 +143,7 @@ public function testAuthorize()
->disableOriginalConstructor()
->getMock();
$extensionAttributes = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
->setMethods(['setVaultPaymentToken'])
->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])
->getMockForAbstractClass();

$commandManagerPool = $this->createMock(CommandManagerPoolInterface::class);
Expand Down Expand Up @@ -235,7 +238,7 @@ public function testCapture()
}

/**
* @covers \Magento\Vault\Model\Method\Vault::isAvailable
* @covers \Magento\Vault\Model\Method\Vault::isAvailable
* @dataProvider isAvailableDataProvider
*/
public function testIsAvailable($isAvailableProvider, $isActive, $expected)
Expand All @@ -251,18 +254,24 @@ public function testIsAvailable($isAvailableProvider, $isActive, $expected)

$config->expects(static::any())
->method('getValue')
->with('active', $storeId)
->with(
'active',
$storeId
)
->willReturn($isActive);

$quote->expects(static::any())
->method('getStoreId')
->willReturn($storeId);

/** @var Vault $model */
$model = $this->objectManager->getObject(Vault::class, [
'config' => $config,
'vaultProvider' => $this->vaultProvider
]);
$model = $this->objectManager->getObject(
Vault::class,
[
'config' => $config,
'vaultProvider' => $this->vaultProvider
]
);
$actual = $model->isAvailable($quote);
static::assertEquals($expected, $actual);
}
Expand Down Expand Up @@ -296,19 +305,25 @@ public function testIsAvailableWithoutQuote()

$config->expects(static::once())
->method('getValue')
->with('active', $quote)
->with(
'active',
$quote
)
->willReturn(false);

/** @var Vault $model */
$model = $this->objectManager->getObject(Vault::class, [
'config' => $config,
'vaultProvider' => $this->vaultProvider
]);
$model = $this->objectManager->getObject(
Vault::class,
[
'config' => $config,
'vaultProvider' => $this->vaultProvider
]
);
static::assertFalse($model->isAvailable($quote));
}

/**
* @covers \Magento\Vault\Model\Method\Vault::canUseInternal
* @covers \Magento\Vault\Model\Method\Vault::canUseInternal
* @param bool|null $configValue
* @param bool|null $paymentValue
* @param bool $expected
Expand All @@ -326,18 +341,24 @@ public function testCanUseInternal($configValue, $paymentValue, $expected)

$handler->expects(static::once())
->method('handle')
->with(['field' => 'can_use_internal'], null)
->with(
['field' => 'can_use_internal'],
null
)
->willReturn($configValue);

$this->vaultProvider->expects(static::any())
->method('canUseInternal')
->willReturn($paymentValue);

/** @var Vault $model */
$model = $this->objectManager->getObject(Vault::class, [
'vaultProvider' => $this->vaultProvider,
'valueHandlerPool' => $handlerPool,
]);
$model = $this->objectManager->getObject(
Vault::class,
[
'vaultProvider' => $this->vaultProvider,
'valueHandlerPool' => $handlerPool,
]
);
static::assertEquals($expected, $model->canUseInternal());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\App\Area;
use Magento\Framework\App\Utility\Files;
use Magento\Framework\Component\ComponentFile;
use Magento\TestFramework\Exception\NoSuchActionException;

/**
Expand Down Expand Up @@ -231,7 +232,7 @@ private function processConfigFile(string $module, string $configFile)
// Read module's routes.xml file
$config = simplexml_load_file($configFile);

$routers = $config->xpath("/config/router");
$routers = $config->xpath("/config/router");
foreach ($routers as $router) {
$routerId = (string)$router['id'];
foreach ($router->xpath('route') as $route) {
Expand All @@ -254,13 +255,11 @@ private function processConfigFile(string $module, string $configFile)
private function getListRoutesXml()
{
if (empty($this->routeConfigFiles)) {
$files = Files::init()->getConfigFiles('*/routes.xml', [], false);
$pattern = '/(?<namespace>[A-Z][a-z]+)[_\/\\\\](?<module>[A-Z][a-zA-Z]+)/';
foreach ($files as $file) {
if (preg_match($pattern, $file, $matches)) {
$module = $matches['namespace'] . '\\' . $matches['module'];
$this->routeConfigFiles[$module][] = $file;
}
$files = Files::init()->getConfigFiles('*/routes.xml', [], false, true);
/** @var ComponentFile $componentFile */
foreach ($files as $componentFile) {
$module = str_replace('_', '\\', $componentFile->getComponentName());
$this->routeConfigFiles[$module][] = $componentFile->getFullPath();
}
}
return $this->routeConfigFiles;
Expand Down
Loading