Skip to content

Commit 3a21f2b

Browse files
authored
ENGCOM-5438: [Unit] Fix broken unit tests #23592
2 parents e30ab27 + 408f20b commit 3a21f2b

File tree

6 files changed

+126
-70
lines changed

6 files changed

+126
-70
lines changed

app/code/Magento/Paypal/Test/Unit/Model/Payflow/TransparentTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
use PHPUnit_Framework_MockObject_MockObject as MockObject;
3030

3131
/**
32+
* Paypal transparent test class
33+
*
3234
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3335
*/
3436
class TransparentTest extends \PHPUnit\Framework\TestCase
@@ -194,7 +196,7 @@ private function getPaymentExtensionInterfaceFactory()
194196
->disableOriginalConstructor()
195197
->getMock();
196198
$orderPaymentExtension = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
197-
->setMethods(['setVaultPaymentToken'])
199+
->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])
198200
->disableOriginalConstructor()
199201
->getMock();
200202

app/code/Magento/Reports/Model/ResourceModel/Product/Collection.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

7-
/**
8-
* @author Magento Core Team <[email protected]>
9-
*/
108
namespace Magento\Reports\Model\ResourceModel\Product;
119

10+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
11+
1212
/**
1313
* Products Report collection.
1414
*
@@ -90,6 +90,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
9090
* @param \Magento\Catalog\Model\Product\Type $productType
9191
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource
9292
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
93+
* @param ProductLimitationFactory|null $productLimitationFactory
9394
*
9495
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
9596
*/
@@ -117,7 +118,8 @@ public function __construct(
117118
\Magento\Reports\Model\Event\TypeFactory $eventTypeFactory,
118119
\Magento\Catalog\Model\Product\Type $productType,
119120
\Magento\Quote\Model\ResourceModel\Quote\Collection $quoteResource,
120-
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null
121+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
122+
ProductLimitationFactory $productLimitationFactory = null
121123
) {
122124
$this->setProductEntityId($product->getEntityIdField());
123125
$this->setProductEntityTableName($product->getEntityTable());
@@ -142,7 +144,8 @@ public function __construct(
142144
$customerSession,
143145
$dateTime,
144146
$groupManagement,
145-
$connection
147+
$connection,
148+
$productLimitationFactory
146149
);
147150
$this->_eventTypeFactory = $eventTypeFactory;
148151
$this->_productType = $productType;

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

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

@@ -12,6 +13,8 @@
1213
use Magento\Catalog\Model\Product\Type as ProductType;
1314
use Magento\Catalog\Model\ResourceModel\Helper;
1415
use Magento\Catalog\Model\ResourceModel\Product as ResourceProduct;
16+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitation;
17+
use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory;
1518
use Magento\Catalog\Model\ResourceModel\Url;
1619
use Magento\Customer\Api\GroupManagementInterface;
1720
use Magento\Customer\Model\Session;
@@ -75,6 +78,11 @@ class CollectionTest extends \PHPUnit\Framework\TestCase
7578
*/
7679
private $selectMock;
7780

81+
/**
82+
* SetUp method
83+
*
84+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
85+
*/
7886
protected function setUp()
7987
{
8088
$this->objectManager = new ObjectManager($this);
@@ -138,31 +146,44 @@ protected function setUp()
138146
$this->resourceMock->expects($this->atLeastOnce())->method('getConnection')->willReturn($this->connectionMock);
139147
$this->connectionMock->expects($this->atLeastOnce())->method('select')->willReturn($this->selectMock);
140148

141-
$this->collection = new ProductCollection(
142-
$entityFactoryMock,
143-
$loggerMock,
144-
$fetchStrategyMock,
145-
$eventManagerMock,
146-
$eavConfigMock,
147-
$this->resourceMock,
148-
$eavEntityFactoryMock,
149-
$resourceHelperMock,
150-
$universalFactoryMock,
151-
$storeManagerMock,
152-
$moduleManagerMock,
153-
$productFlatStateMock,
154-
$scopeConfigMock,
155-
$optionFactoryMock,
156-
$catalogUrlMock,
157-
$localeDateMock,
158-
$customerSessionMock,
159-
$dateTimeMock,
160-
$groupManagementMock,
161-
$productMock,
162-
$this->eventTypeFactoryMock,
163-
$productTypeMock,
164-
$quoteResourceMock,
165-
$this->connectionMock
149+
$productLimitationFactoryMock = $this->createPartialMock(
150+
ProductLimitationFactory::class,
151+
['create']
152+
);
153+
$productLimitation = $this->createMock(ProductLimitation::class);
154+
$productLimitationFactoryMock->expects($this->once())
155+
->method('create')
156+
->willReturn($productLimitation);
157+
158+
$this->collection = $this->objectManager->getObject(
159+
ProductCollection::class,
160+
[
161+
'entityFactory' => $entityFactoryMock,
162+
'logger' => $loggerMock,
163+
'fetchStrategy' => $fetchStrategyMock,
164+
'eventManager' => $eventManagerMock,
165+
'eavConfig' => $eavConfigMock,
166+
'resource' => $this->resourceMock,
167+
'eavEntityFactory' => $eavEntityFactoryMock,
168+
'resourceHelper' => $resourceHelperMock,
169+
'universalFactory' => $universalFactoryMock,
170+
'storeManager' => $storeManagerMock,
171+
'moduleManager' => $moduleManagerMock,
172+
'catalogProductFlatState' => $productFlatStateMock,
173+
'scopeConfig' => $scopeConfigMock,
174+
'productOptionFactory' => $optionFactoryMock,
175+
'catalogUrl' => $catalogUrlMock,
176+
'localeDate' => $localeDateMock,
177+
'customerSession' => $customerSessionMock,
178+
'dateTime' => $dateTimeMock,
179+
'groupManagement' => $groupManagementMock,
180+
'product' => $productMock,
181+
'eventTypeFactory' => $this->eventTypeFactoryMock,
182+
'productType' => $productTypeMock,
183+
'quoteResource' => $quoteResourceMock,
184+
'connection' => $this->connectionMock,
185+
'productLimitationFactory' => $productLimitationFactoryMock
186+
]
166187
);
167188
}
168189

app/code/Magento/Vault/Test/Unit/Model/Method/VaultTest.php

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Vault\Test\Unit\Model\Method;
79

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

2628
/**
2729
* Class VaultTest
30+
*
2831
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2932
*/
3033
class VaultTest extends \PHPUnit\Framework\TestCase
@@ -140,7 +143,7 @@ public function testAuthorize()
140143
->disableOriginalConstructor()
141144
->getMock();
142145
$extensionAttributes = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
143-
->setMethods(['setVaultPaymentToken'])
146+
->setMethods(['setVaultPaymentToken', 'getVaultPaymentToken'])
144147
->getMockForAbstractClass();
145148

146149
$commandManagerPool = $this->createMock(CommandManagerPoolInterface::class);
@@ -235,7 +238,7 @@ public function testCapture()
235238
}
236239

237240
/**
238-
* @covers \Magento\Vault\Model\Method\Vault::isAvailable
241+
* @covers \Magento\Vault\Model\Method\Vault::isAvailable
239242
* @dataProvider isAvailableDataProvider
240243
*/
241244
public function testIsAvailable($isAvailableProvider, $isActive, $expected)
@@ -251,18 +254,24 @@ public function testIsAvailable($isAvailableProvider, $isActive, $expected)
251254

252255
$config->expects(static::any())
253256
->method('getValue')
254-
->with('active', $storeId)
257+
->with(
258+
'active',
259+
$storeId
260+
)
255261
->willReturn($isActive);
256262

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

261267
/** @var Vault $model */
262-
$model = $this->objectManager->getObject(Vault::class, [
263-
'config' => $config,
264-
'vaultProvider' => $this->vaultProvider
265-
]);
268+
$model = $this->objectManager->getObject(
269+
Vault::class,
270+
[
271+
'config' => $config,
272+
'vaultProvider' => $this->vaultProvider
273+
]
274+
);
266275
$actual = $model->isAvailable($quote);
267276
static::assertEquals($expected, $actual);
268277
}
@@ -296,19 +305,25 @@ public function testIsAvailableWithoutQuote()
296305

297306
$config->expects(static::once())
298307
->method('getValue')
299-
->with('active', $quote)
308+
->with(
309+
'active',
310+
$quote
311+
)
300312
->willReturn(false);
301313

302314
/** @var Vault $model */
303-
$model = $this->objectManager->getObject(Vault::class, [
304-
'config' => $config,
305-
'vaultProvider' => $this->vaultProvider
306-
]);
315+
$model = $this->objectManager->getObject(
316+
Vault::class,
317+
[
318+
'config' => $config,
319+
'vaultProvider' => $this->vaultProvider
320+
]
321+
);
307322
static::assertFalse($model->isAvailable($quote));
308323
}
309324

310325
/**
311-
* @covers \Magento\Vault\Model\Method\Vault::canUseInternal
326+
* @covers \Magento\Vault\Model\Method\Vault::canUseInternal
312327
* @param bool|null $configValue
313328
* @param bool|null $paymentValue
314329
* @param bool $expected
@@ -326,18 +341,24 @@ public function testCanUseInternal($configValue, $paymentValue, $expected)
326341

327342
$handler->expects(static::once())
328343
->method('handle')
329-
->with(['field' => 'can_use_internal'], null)
344+
->with(
345+
['field' => 'can_use_internal'],
346+
null
347+
)
330348
->willReturn($configValue);
331349

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

336354
/** @var Vault $model */
337-
$model = $this->objectManager->getObject(Vault::class, [
338-
'vaultProvider' => $this->vaultProvider,
339-
'valueHandlerPool' => $handlerPool,
340-
]);
355+
$model = $this->objectManager->getObject(
356+
Vault::class,
357+
[
358+
'vaultProvider' => $this->vaultProvider,
359+
'valueHandlerPool' => $handlerPool,
360+
]
361+
);
341362
static::assertEquals($expected, $model->canUseInternal());
342363
}
343364

dev/tests/static/framework/Magento/TestFramework/Dependency/Route/RouteMapper.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\Area;
1111
use Magento\Framework\App\Utility\Files;
12+
use Magento\Framework\Component\ComponentFile;
1213
use Magento\TestFramework\Exception\NoSuchActionException;
1314

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

234-
$routers = $config->xpath("/config/router");
235+
$routers = $config->xpath("/config/router");
235236
foreach ($routers as $router) {
236237
$routerId = (string)$router['id'];
237238
foreach ($router->xpath('route') as $route) {
@@ -254,13 +255,11 @@ private function processConfigFile(string $module, string $configFile)
254255
private function getListRoutesXml()
255256
{
256257
if (empty($this->routeConfigFiles)) {
257-
$files = Files::init()->getConfigFiles('*/routes.xml', [], false);
258-
$pattern = '/(?<namespace>[A-Z][a-z]+)[_\/\\\\](?<module>[A-Z][a-zA-Z]+)/';
259-
foreach ($files as $file) {
260-
if (preg_match($pattern, $file, $matches)) {
261-
$module = $matches['namespace'] . '\\' . $matches['module'];
262-
$this->routeConfigFiles[$module][] = $file;
263-
}
258+
$files = Files::init()->getConfigFiles('*/routes.xml', [], false, true);
259+
/** @var ComponentFile $componentFile */
260+
foreach ($files as $componentFile) {
261+
$module = str_replace('_', '\\', $componentFile->getComponentName());
262+
$this->routeConfigFiles[$module][] = $componentFile->getFullPath();
264263
}
265264
}
266265
return $this->routeConfigFiles;

0 commit comments

Comments
 (0)