Skip to content

Commit 24a4978

Browse files
author
Igor Melnikov
committed
MAGETWO-67871: Requesting autogenerated classes that are not in constructor cause fatal errors in production mode
- refactor
1 parent a90311d commit 24a4978

File tree

21 files changed

+146
-302
lines changed

21 files changed

+146
-302
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,14 @@ public function testTierPrices($priceScope, $expectedWebsiteId)
236236
$this->assertEquals($tps[$i]->getQty(), $tpData['price_qty'], 'Qty does not match');
237237
}
238238

239-
$tierPriceExtention = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
239+
$tierPriceExtensionMock = $this->getMockBuilder(ProductTierPriceExtensionInterface::class)
240240
->setMethods(['getWebsiteId', 'setWebsiteId', 'getPercentageValue', 'setPercentageValue'])
241241
->getMock();
242-
$tierPriceExtention->expects($this->any())->method('getPercentageValue')->willReturn(50);
243-
$tierPriceExtention->expects($this->any())->method('setWebsiteId');
244-
$this->tierPriceExtensionFactoryMock->expects($this->any())->method('create')->willReturn($tierPriceExtention);
242+
$tierPriceExtensionMock->expects($this->any())->method('getPercentageValue')->willReturn(50);
243+
$tierPriceExtensionMock->expects($this->any())->method('setWebsiteId');
244+
$this->tierPriceExtensionFactoryMock->expects($this->any())
245+
->method('create')
246+
->willReturn($tierPriceExtensionMock);
245247

246248
// test with the data retrieved as a REST object
247249
$tpRests = $this->model->getTierPrices($this->product);

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/FileTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class FileTest extends AbstractFormTestCase
2121
*/
2222
private $urlEncode;
2323

24-
/**@var \PHPUnit_Framework_MockObject_MockObject|NotProtectedExtension
24+
/**
25+
* @var \PHPUnit_Framework_MockObject_MockObject|NotProtectedExtension
2526
*/
2627
private $fileValidatorMock;
2728

app/code/Magento/Directory/Model/Currency/Import/Webservicex.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Directory\Model\Currency\Import;
87

98
/**
@@ -14,9 +13,8 @@ class Webservicex extends \Magento\Directory\Model\Currency\Import\AbstractImpor
1413
/**
1514
* Currency converter url
1615
*/
17-
// @codingStandardsIgnoreStart
18-
const CURRENCY_CONVERTER_URL = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate?FromCurrency={{CURRENCY_FROM}}&ToCurrency={{CURRENCY_TO}}';
19-
// @codingStandardsIgnoreEnd
16+
const CURRENCY_CONVERTER_URL = 'http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate'
17+
. '?FromCurrency={{CURRENCY_FROM}}&ToCurrency={{CURRENCY_TO}}';
2018

2119
/**
2220
* Http Client Factory

app/code/Magento/Quote/Model/QuoteRepository.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
4747

4848
/**
4949
* @var \Magento\Quote\Model\ResourceModel\Quote\Collection
50+
* @deprecated
5051
*/
5152
protected $quoteCollection;
5253

@@ -81,6 +82,8 @@ class QuoteRepository implements \Magento\Quote\Api\CartRepositoryInterface
8182
private $quoteCollectionFactory;
8283

8384
/**
85+
* Constructor
86+
*
8487
* @param QuoteFactory $quoteFactory
8588
* @param StoreManagerInterface $storeManager
8689
* @param \Magento\Quote\Model\ResourceModel\Quote\Collection $quoteCollection
@@ -232,7 +235,7 @@ protected function getQuoteCollection()
232235
*/
233236
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
234237
{
235-
$this->quoteCollection = $this->getQuoteCollection();
238+
$this->quoteCollection = $this->quoteCollectionFactory->create();
236239
/** @var \Magento\Quote\Api\Data\CartSearchResultsInterface $searchData */
237240
$searchData = $this->searchResultsDataFactory->create();
238241
$searchData->setSearchCriteria($searchCriteria);

app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Conditions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $fo
143143
{
144144
if (!$model) {
145145
$id = $this->getRequest()->getParam('id');
146-
$model = $this->getRuleFactory()->create();
146+
$model = $this->ruleFactory->create();
147147
$model->load($id);
148148
}
149149
$conditionsFieldSetId = $model->getConditionsFieldSetId($formName);

dev/tests/static/framework/Magento/TestFramework/Utility/AutogeneratedClassNotInConstructorFinder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function find($fileContent)
4545

4646
if (isset($shortNameMatches[2])) {
4747
foreach ($shortNameMatches[2] as $shortName) {
48-
if (strpos($shortName, 'Magento') === false && substr($shortName, 0, 1) !== '\\') {
48+
if (substr($shortName, 0, 1) !== '\\') {
4949
$class = $this->matchPartialNamespace($fileContent, $shortName);
5050
} else {
5151
$class = $shortName;
@@ -85,8 +85,8 @@ private function getConstructorArguments($className)
8585
$classParameters = $constructor->getParameters();
8686
foreach ($classParameters as $classParameter) {
8787
if ($classParameter->getType()) {
88-
$parameterName = $classParameter->getType();
89-
$arguments[] = ltrim($parameterName, '\\');
88+
$parameterType = $classParameter->getType();
89+
$arguments[] = ltrim($parameterType, '\\');
9090
}
9191
}
9292
}

dev/tests/static/framework/Magento/TestFramework/Utility/ChangedFiles.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\TestFramework\Utility;
88

99
use Magento\Framework\App\Utility\Files;
10-
use Magento\TestFramework\Utility\File\RegexIteratorFactory;
1110

1211
/**
1312
* A helper to gather various changed files
@@ -25,11 +24,12 @@ class ChangedFiles
2524
* Returns array of PHP-files, that use or declare Magento application classes and Magento libs
2625
*
2726
* @param string $changedFilesList
27+
* @param int $fileTypes
2828
* @return array
2929
*/
30-
public static function getPhpFiles($changedFilesList)
30+
public static function getPhpFiles($changedFilesList, $fileTypes = 0)
3131
{
32-
$fileUtilities = new File(Files::init(), new RegexIteratorFactory());
32+
$fileUtilities = Files::init();
3333
if (isset($_ENV['INCREMENTAL_BUILD'])) {
3434
$phpFiles = [];
3535
foreach (glob($changedFilesList) as $listFile) {
@@ -43,10 +43,10 @@ function (&$file) {
4343
);
4444
if (!empty($phpFiles)) {
4545
$phpFiles = Files::composeDataSets($phpFiles);
46-
$phpFiles = array_intersect_key($phpFiles, $fileUtilities->getPhpFiles());
46+
$phpFiles = array_intersect_key($phpFiles, $fileUtilities->getPhpFiles($fileTypes));
4747
}
4848
} else {
49-
$phpFiles = $fileUtilities->getPhpFiles();
49+
$phpFiles = $fileUtilities->getPhpFiles($fileTypes);
5050
}
5151

5252
return $phpFiles;

dev/tests/static/framework/Magento/TestFramework/Utility/ClassNameExtractor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public function getNameWithNamespace($fileContent)
1717
{
1818
$namespace = $this->getNamespace($fileContent);
1919
$name = $this->getName($fileContent);
20-
if ($namespace && $name) {
21-
return $namespace . '\\' . $name;
20+
if ($name) {
21+
return $namespace ? $namespace . '\\' . $name : $name;
2222
}
2323
return false;
2424
}
@@ -34,7 +34,7 @@ public function getName($fileContent)
3434
$namespace = $this->getNamespace($fileContent);
3535
if (isset($namespace)) {
3636
preg_match_all(
37-
'/^(class|abstract\sclass|interface)\s([a-z0-9]+)(\sextends|\simplements|$)/im',
37+
'/^\s*(class|abstract\sclass|interface)\s+([a-z0-9]+)(\s+(extends|implements)|\s*$)/im',
3838
$fileContent,
3939
$classMatches
4040
);

dev/tests/static/framework/Magento/TestFramework/Utility/File.php

Lines changed: 0 additions & 97 deletions
This file was deleted.

dev/tests/static/framework/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
$dirSearch = new DirSearch($componentRegistrar, new ReadFactory(new DriverPool()));
2121
$themePackageList = new ThemePackageList($componentRegistrar, new ThemePackageFactory());
2222
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
23+
$regexIteratorFactory = new Magento\Framework\App\Utility\RegexIteratorFactory();
2324
\Magento\Framework\App\Utility\Files::setInstance(
24-
new Files($componentRegistrar, $dirSearch, $themePackageList, $serializer)
25+
new Files($componentRegistrar, $dirSearch, $themePackageList, $serializer, $regexIteratorFactory)
2526
);
2627

2728
/**

0 commit comments

Comments
 (0)