Skip to content

Commit dc6e518

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 9602a92 commit dc6e518

File tree

5 files changed

+115
-91
lines changed

5 files changed

+115
-91
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/ImageTest.php

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,82 +21,72 @@ class ImageTest extends \PHPUnit_Framework_TestCase
2121
/**
2222
* @var \Magento\Catalog\Model\Product\Image
2323
*/
24-
protected $image;
24+
private $image;
2525

2626
/**
2727
* @var \Magento\Framework\Model\Context|\PHPUnit_Framework_MockObject_MockObject
2828
*/
29-
protected $context;
30-
31-
/**
32-
* @var \Magento\Framework\Registry|\PHPUnit_Framework_MockObject_MockObject
33-
*/
34-
protected $registry;
29+
private $context;
3530

3631
/**
3732
* @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
3833
*/
39-
protected $storeManager;
34+
private $storeManager;
4035

4136
/**
4237
* @var \Magento\Catalog\Model\Product\Media\Config|\PHPUnit_Framework_MockObject_MockObject
4338
*/
44-
protected $config;
39+
private $config;
4540

4641
/**
4742
* @var \Magento\MediaStorage\Helper\File\Storage\Database|\PHPUnit_Framework_MockObject_MockObject
4843
*/
49-
protected $coreFileHelper;
44+
private $coreFileHelper;
5045

5146
/**
5247
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
5348
*/
54-
protected $filesystem;
49+
private $filesystem;
5550

5651
/**
5752
* @var \Magento\Framework\Image\Factory|\PHPUnit_Framework_MockObject_MockObject
5853
*/
59-
protected $factory;
54+
private $factory;
6055

6156
/**
6257
* @var \Magento\Framework\View\Asset\Repository|\PHPUnit_Framework_MockObject_MockObject
6358
*/
64-
protected $repository;
59+
private $repository;
6560

6661
/**
6762
* @var \Magento\Framework\View\FileSystem|\PHPUnit_Framework_MockObject_MockObject
6863
*/
69-
protected $fileSystem;
70-
71-
/**
72-
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
73-
*/
74-
protected $scopeConfigInterface;
64+
private $fileSystem;
7565

7666
/**
7767
* @var \Magento\Framework\Filesystem\Directory\WriteInterface|\PHPUnit_Framework_MockObject_MockObject
7868
*/
79-
protected $mediaDirectory;
69+
private $mediaDirectory;
8070

8171
/**
8272
* @var \Magento\Framework\View\Asset\LocalInterface|\PHPUnit_Framework_MockObject_MockObject
8373
*/
84-
protected $imageAsset;
74+
private $imageAsset;
8575

8676
/**
8777
* @var ImageFactory|\PHPUnit_Framework_MockObject_MockObject
8878
*/
89-
protected $viewAssetImageFactory;
79+
private $viewAssetImageFactory;
9080

9181
/**
9282
* @var PlaceholderFactory|\PHPUnit_Framework_MockObject_MockObject
9383
*/
94-
protected $viewAssetPlaceholderFactory;
84+
private $viewAssetPlaceholderFactory;
9585

9686
protected function setUp()
9787
{
88+
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
9889
$this->context = $this->getMock(\Magento\Framework\Model\Context::class, [], [], '', false);
99-
$this->registry = $this->getMock(\Magento\Framework\Registry::class);
10090

10191
$this->storeManager = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class)
10292
->disableOriginalConstructor()
@@ -125,11 +115,7 @@ protected function setUp()
125115
$this->factory = $this->getMock(\Magento\Framework\Image\Factory::class, [], [], '', false);
126116
$this->repository = $this->getMock(\Magento\Framework\View\Asset\Repository::class, [], [], '', false);
127117
$this->fileSystem = $this->getMock(\Magento\Framework\View\FileSystem::class, [], [], '', false);
128-
$this->scopeConfigInterface = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
129118

130-
$context = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
131-
->disableOriginalConstructor()
132-
->getMock();
133119
$this->viewAssetImageFactory = $this->getMockBuilder(ImageFactory::class)
134120
->disableOriginalConstructor()
135121
->setMethods(['create'])
@@ -139,22 +125,22 @@ protected function setUp()
139125
->setMethods(['create'])
140126
->getMock();
141127

142-
$this->image = new \Magento\Catalog\Model\Product\Image(
143-
$context,
144-
$this->registry,
145-
$this->storeManager,
146-
$this->config,
147-
$this->coreFileHelper,
148-
$this->filesystem,
149-
$this->factory,
150-
$this->repository,
151-
$this->fileSystem,
152-
$this->scopeConfigInterface,
153-
null,
154-
null,
155-
[],
156-
$this->viewAssetImageFactory,
157-
$this->viewAssetPlaceholderFactory
128+
$this->image = $objectManager->getObject(
129+
\Magento\Catalog\Model\Product\Image::class,
130+
[
131+
'storeManager' => $this->storeManager,
132+
'catalogProductMediaConfig' => $this->config,
133+
'coreFileStorageDatabase' => $this->coreFileHelper,
134+
'filesystem' => $this->filesystem,
135+
'imageFactory' => $this->factory,
136+
'assetRepo' => $this->repository,
137+
'viewFileSystem' => $this->fileSystem,
138+
'resource' => null,
139+
'resourceCollection' => null,
140+
'data' => [],
141+
'viewAssetImageFactory' => $this->viewAssetImageFactory,
142+
'viewAssetPlaceholderFactory' => $this->viewAssetPlaceholderFactory
143+
]
158144
);
159145

160146
// Settings for backward compatible property

app/code/Magento/Customer/Controller/Adminhtml/Index.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ abstract class Index extends \Magento\Backend\App\Action
3535

3636
/**
3737
* @var \Magento\Framework\Validator
38+
* @deprecated
3839
*/
3940
protected $_validator;
4041

@@ -52,36 +53,50 @@ abstract class Index extends \Magento\Backend\App\Action
5253

5354
/**
5455
* @var \Magento\Customer\Model\CustomerFactory
56+
* @deprecated
5557
*/
5658
protected $_customerFactory = null;
5759

5860
/**
5961
* @var \Magento\Customer\Model\AddressFactory
62+
* @deprecated
6063
*/
6164
protected $_addressFactory = null;
6265

63-
/** @var \Magento\Newsletter\Model\SubscriberFactory */
66+
/**
67+
* @var \Magento\Newsletter\Model\SubscriberFactory
68+
*/
6469
protected $_subscriberFactory;
6570

6671
/**
6772
* @var \Magento\Customer\Model\Metadata\FormFactory
6873
*/
6974
protected $_formFactory;
7075

71-
/** @var CustomerRepositoryInterface */
76+
/**
77+
* @var CustomerRepositoryInterface
78+
*/
7279
protected $_customerRepository;
7380

74-
/** @var \Magento\Customer\Helper\View */
81+
/**
82+
* @var \Magento\Customer\Helper\View
83+
*/
7584
protected $_viewHelper;
7685

77-
/** @var \Magento\Framework\Math\Random */
86+
/**
87+
* @var \Magento\Framework\Math\Random
88+
* @deprecated
89+
*/
7890
protected $_random;
7991

80-
/** @var ObjectFactory */
92+
/**
93+
* @var ObjectFactory
94+
*/
8195
protected $_objectFactory;
8296

8397
/**
8498
* @var \Magento\Framework\Api\ExtensibleDataObjectConverter
99+
* @deprecated
85100
*/
86101
protected $_extensibleDataObjectConverter;
87102

@@ -117,6 +132,7 @@ abstract class Index extends \Magento\Backend\App\Action
117132

118133
/**
119134
* @var \Magento\Framework\Reflection\DataObjectProcessor
135+
* @deprecated
120136
*/
121137
protected $dataObjectProcessor;
122138

@@ -127,6 +143,7 @@ abstract class Index extends \Magento\Backend\App\Action
127143

128144
/**
129145
* @var \Magento\Framework\View\LayoutFactory
146+
* @deprecated
130147
*/
131148
protected $layoutFactory;
132149

@@ -151,6 +168,8 @@ abstract class Index extends \Magento\Backend\App\Action
151168
protected $resultJsonFactory;
152169

153170
/**
171+
* Constructor
172+
*
154173
* @param \Magento\Backend\App\Action\Context $context
155174
* @param \Magento\Framework\Registry $coreRegistry
156175
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
@@ -176,7 +195,6 @@ abstract class Index extends \Magento\Backend\App\Action
176195
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
177196
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
178197
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
179-
*
180198
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
181199
*/
182200
public function __construct(
@@ -288,6 +306,7 @@ protected function _addSessionErrorMessages($messages)
288306
* @param callable $singleAction A single action callable that takes a customer ID as input
289307
* @param int[] $customerIds Array of customer Ids to perform the action upon
290308
* @return int Number of customers successfully acted upon
309+
* @deprecated
291310
*/
292311
protected function actUponMultipleCustomers(callable $singleAction, $customerIds)
293312
{

app/code/Magento/Eav/Test/Unit/Model/AttributeManagementTest.php

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77

88
use Magento\Eav\Model\AttributeManagement;
99
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory;
11+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
12+
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection;
13+
use Magento\Eav\Model\Config;
14+
use Magento\Eav\Model\ConfigFactory;
15+
use Magento\Eav\Api\AttributeGroupRepositoryInterface;
16+
use Magento\Eav\Api\AttributeRepositoryInterface;
17+
use Magento\Eav\Model\ResourceModel\Entity\Attribute;
1018

1119
/**
1220
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -20,63 +28,66 @@ class AttributeManagementTest extends \PHPUnit_Framework_TestCase
2028
private $attributeManagement;
2129

2230
/**
23-
* @var \PHPUnit_Framework_MockObject_MockObject
31+
* @var AttributeSetRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
2432
*/
2533
private $setRepositoryMock;
2634

2735
/**
28-
* @var \PHPUnit_Framework_MockObject_MockObject
36+
* @var Collection|\PHPUnit_Framework_MockObject_MockObject
2937
*/
3038
private $attributeCollectionMock;
3139

3240
/**
33-
* @var \PHPUnit_Framework_MockObject_MockObject
41+
* @var Config|\PHPUnit_Framework_MockObject_MockObject
3442
*/
3543
private $eavConfigMock;
3644

3745
/**
38-
* @var \PHPUnit_Framework_MockObject_MockObject
46+
* @var ConfigFactory|\PHPUnit_Framework_MockObject_MockObject
3947
*/
4048
private $entityTypeFactoryMock;
4149

4250
/**
43-
* @var \PHPUnit_Framework_MockObject_MockObject
51+
* @var AttributeGroupRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
4452
*/
4553
private $groupRepositoryMock;
4654

4755
/**
48-
* @var \PHPUnit_Framework_MockObject_MockObject
56+
* @var AttributeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
4957
*/
5058
private $attributeRepositoryMock;
5159

5260
/**
53-
* @var \PHPUnit_Framework_MockObject_MockObject
61+
* @var Attribute|\PHPUnit_Framework_MockObject_MockObject
5462
*/
5563
private $attributeResourceMock;
5664

65+
/**
66+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
67+
*/
68+
private $attributeCollectionFactoryMock;
69+
5770
protected function setUp()
5871
{
5972
$this->setRepositoryMock =
60-
$this->getMock(\Magento\Eav\Api\AttributeSetRepositoryInterface::class, [], [], '', false);
73+
$this->getMock(AttributeSetRepositoryInterface::class, [], [], '', false);
6174
$this->attributeCollectionMock =
62-
$this->getMock(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection::class, [], [], '', false);
75+
$this->getMock(Collection::class, [], [], '', false);
6376
$this->eavConfigMock =
64-
$this->getMock(\Magento\Eav\Model\Config::class, [], [], '', false);
77+
$this->getMock(Config::class, [], [], '', false);
6578
$this->entityTypeFactoryMock =
66-
$this->getMock(\Magento\Eav\Model\ConfigFactory::class, ['create', '__wakeup'], [], '', false);
79+
$this->getMock(ConfigFactory::class, ['create', '__wakeup'], [], '', false);
6780
$this->groupRepositoryMock =
68-
$this->getMock(\Magento\Eav\Api\AttributeGroupRepositoryInterface::class, [], [], '', false);
81+
$this->getMock(AttributeGroupRepositoryInterface::class, [], [], '', false);
6982
$this->attributeRepositoryMock =
70-
$this->getMock(\Magento\Eav\Api\AttributeRepositoryInterface::class, [], [], '', false);
83+
$this->getMock(AttributeRepositoryInterface::class, [], [], '', false);
7184
$this->attributeResourceMock =
72-
$this->getMock(\Magento\Eav\Model\ResourceModel\Entity\Attribute::class, [], [], '', false);
73-
$this->attributeCollectionFactoryMock = $this->getMockBuilder(
74-
\Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory::class
75-
)
85+
$this->getMock(Attribute::class, [], [], '', false);
86+
$this->attributeCollectionFactoryMock = $this->getMockBuilder(CollectionFactory::class)
7687
->disableOriginalConstructor()
7788
->getMock();
7889

79-
$this->attributeManagement = new \Magento\Eav\Model\AttributeManagement(
90+
$this->attributeManagement = new AttributeManagement(
8091
$this->setRepositoryMock,
8192
$this->attributeCollectionMock,
8293
$this->eavConfigMock,

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -219,17 +219,6 @@ protected function loadQuote($loadMethod, $loadField, $identifier, array $shared
219219
return $quote;
220220
}
221221

222-
/**
223-
* Get quote collection
224-
*
225-
* @deprecated
226-
* @return QuoteCollection
227-
*/
228-
protected function getQuoteCollection()
229-
{
230-
return $this->quoteCollectionFactory->create();
231-
}
232-
233222
/**
234223
* {@inheritdoc}
235224
*/

0 commit comments

Comments
 (0)