Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test / Deprecate / ObjectManager Helper #29272

Merged
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 @@ -5,9 +5,12 @@
*/
namespace Magento\Framework\TestFramework\Unit\Helper;

use PHPUnit\Framework\MockObject\MockObject;

/**
* Helper class for basic object retrieving, such as blocks, models etc...
*
* @deprecated Class under test should be instantiated with `new` keyword with explicit dependencies declaration
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ObjectManager
Expand Down Expand Up @@ -44,7 +47,7 @@ public function __construct(\PHPUnit\Framework\TestCase $testObject)
*
* @param string $argClassName
* @param array $originalArguments
* @return null|object|\PHPUnit_Framework_MockObject_MockObject
* @return null|object|MockObject
*/
protected function _createArgumentMock($argClassName, array $originalArguments)
{
Expand Down Expand Up @@ -82,7 +85,7 @@ protected function _processSpecialCases($className, $arguments)
/**
* Retrieve specific mock of core resource model
*
* @return \Magento\Framework\Module\ResourceInterface|\PHPUnit_Framework_MockObject_MockObject
* @return \Magento\Framework\Module\ResourceInterface|MockObject
*/
protected function _getResourceModelMock()
{
Expand All @@ -108,7 +111,7 @@ protected function _getResourceModelMock()
* Retrieve mock of core translator model
*
* @param string $className
* @return \Magento\Framework\TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
* @return \Magento\Framework\TranslateInterface|MockObject
*/
protected function _getTranslatorMock($className)
{
Expand All @@ -130,7 +133,7 @@ protected function _getTranslatorMock($className)
* Get mock without call of original constructor
*
* @param string $className
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
*/
protected function _getMockWithoutConstructorCall($className)
{
Expand All @@ -152,6 +155,7 @@ protected function _getMockWithoutConstructorCall($className)
*/
public function getObject($className, array $arguments = [])
{
// phpstan:ignore
if (is_subclass_of($className, \Magento\Framework\Api\AbstractSimpleObjectBuilder::class)
|| is_subclass_of($className, \Magento\Framework\Api\Builder::class)
) {
Expand Down Expand Up @@ -292,7 +296,7 @@ public function getConstructArguments($className, array $arguments = [])
*
* @param string $className
* @param array $data
* @return \PHPUnit_Framework_MockObject_MockObject
* @return MockObject
* @throws \InvalidArgumentException
*/
public function getCollectionMock($className, array $data)
Expand Down Expand Up @@ -326,17 +330,16 @@ public function getCollectionMock($className, array $data)
*
* @param string $argClassName
* @param array $arguments
* @return null|object|\PHPUnit_Framework_MockObject_MockObject
* @return null|object|MockObject
*/
private function _getMockObject($argClassName, array $arguments)
{
// phpstan:ignore
if (is_subclass_of($argClassName, \Magento\Framework\Api\ExtensibleObjectBuilder::class)) {
$object = $this->getBuilder($argClassName, $arguments);
return $object;
} else {
$object = $this->_createArgumentMock($argClassName, $arguments);
return $object;
return $this->getBuilder($argClassName, $arguments);
}

return $this->_createArgumentMock($argClassName, $arguments);
}

/**
Expand Down