Skip to content

Commit 3e0aa39

Browse files
authored
ENGCOM-7886: Unit Test / Deprecate / ObjectManager Helper #29272
2 parents 40b423c + 3367443 commit 3e0aa39

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/internal/Magento/Framework/TestFramework/Unit/Helper/ObjectManager.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66
namespace Magento\Framework\TestFramework\Unit\Helper;
77

8+
use PHPUnit\Framework\MockObject\MockObject;
9+
810
/**
911
* Helper class for basic object retrieving, such as blocks, models etc...
1012
*
13+
* @deprecated Class under test should be instantiated with `new` keyword with explicit dependencies declaration
1114
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1215
*/
1316
class ObjectManager
@@ -44,7 +47,7 @@ public function __construct(\PHPUnit\Framework\TestCase $testObject)
4447
*
4548
* @param string $argClassName
4649
* @param array $originalArguments
47-
* @return null|object|\PHPUnit_Framework_MockObject_MockObject
50+
* @return null|object|MockObject
4851
*/
4952
protected function _createArgumentMock($argClassName, array $originalArguments)
5053
{
@@ -82,7 +85,7 @@ protected function _processSpecialCases($className, $arguments)
8285
/**
8386
* Retrieve specific mock of core resource model
8487
*
85-
* @return \Magento\Framework\Module\ResourceInterface|\PHPUnit_Framework_MockObject_MockObject
88+
* @return \Magento\Framework\Module\ResourceInterface|MockObject
8689
*/
8790
protected function _getResourceModelMock()
8891
{
@@ -108,7 +111,7 @@ protected function _getResourceModelMock()
108111
* Retrieve mock of core translator model
109112
*
110113
* @param string $className
111-
* @return \Magento\Framework\TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
114+
* @return \Magento\Framework\TranslateInterface|MockObject
112115
*/
113116
protected function _getTranslatorMock($className)
114117
{
@@ -130,7 +133,7 @@ protected function _getTranslatorMock($className)
130133
* Get mock without call of original constructor
131134
*
132135
* @param string $className
133-
* @return \PHPUnit_Framework_MockObject_MockObject
136+
* @return MockObject
134137
*/
135138
protected function _getMockWithoutConstructorCall($className)
136139
{
@@ -152,6 +155,7 @@ protected function _getMockWithoutConstructorCall($className)
152155
*/
153156
public function getObject($className, array $arguments = [])
154157
{
158+
// phpstan:ignore
155159
if (is_subclass_of($className, \Magento\Framework\Api\AbstractSimpleObjectBuilder::class)
156160
|| is_subclass_of($className, \Magento\Framework\Api\Builder::class)
157161
) {
@@ -292,7 +296,7 @@ public function getConstructArguments($className, array $arguments = [])
292296
*
293297
* @param string $className
294298
* @param array $data
295-
* @return \PHPUnit_Framework_MockObject_MockObject
299+
* @return MockObject
296300
* @throws \InvalidArgumentException
297301
*/
298302
public function getCollectionMock($className, array $data)
@@ -326,17 +330,16 @@ public function getCollectionMock($className, array $data)
326330
*
327331
* @param string $argClassName
328332
* @param array $arguments
329-
* @return null|object|\PHPUnit_Framework_MockObject_MockObject
333+
* @return null|object|MockObject
330334
*/
331335
private function _getMockObject($argClassName, array $arguments)
332336
{
337+
// phpstan:ignore
333338
if (is_subclass_of($argClassName, \Magento\Framework\Api\ExtensibleObjectBuilder::class)) {
334-
$object = $this->getBuilder($argClassName, $arguments);
335-
return $object;
336-
} else {
337-
$object = $this->_createArgumentMock($argClassName, $arguments);
338-
return $object;
339+
return $this->getBuilder($argClassName, $arguments);
339340
}
341+
342+
return $this->_createArgumentMock($argClassName, $arguments);
340343
}
341344

342345
/**

0 commit comments

Comments
 (0)