Skip to content

Commit c1b9da1

Browse files
committed
MAGETWO-69240: Unit Tests have different behavior between run for a bunch and a single test
1 parent a893a9f commit c1b9da1

File tree

2 files changed

+6
-77
lines changed

2 files changed

+6
-77
lines changed

lib/internal/Magento/Framework/TestFramework/Unit/Listener/ReplaceObjectManager.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,29 @@
99

1010
use Magento\Framework\App\ObjectManager;
1111
use Magento\Framework\ObjectManagerInterface;
12-
use Magento\Framework\TestFramework\Unit\Model\ObjectManager as ObjectManagerMock;
1312

1413
/**
1514
* The event listener which instantiates ObjectManager before test run
1615
*/
1716
class ReplaceObjectManager extends \PHPUnit_Framework_BaseTestListener
1817
{
19-
/**
20-
* @var ObjectManagerInterface
21-
*/
22-
private $objectManager;
23-
2418
/**
2519
* Replaces ObjectManager before run for each test
2620
*
27-
* Replace existing instance of the Application's ObjectManager with an instance,
28-
* defined in the Unit Test framework
21+
* Replace existing instance of the Application's ObjectManager with the mock.
2922
*
3023
* This avoids the issue with a not initialized ObjectManager
31-
* and allows to customize its behaviour with expected for unit testing
24+
* and makes working with ObjectManager predictable as it always contains clear mock for each test
3225
*
3326
* @param \PHPUnit_Framework_Test $test
3427
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3528
*/
3629
public function startTest(\PHPUnit_Framework_Test $test)
3730
{
38-
if (!$this->objectManager) {
39-
$this->objectManager = new ObjectManagerMock();
31+
if ($test instanceof \PHPUnit_Framework_TestCase) {
32+
$objectManagerMock = $test->getMockBuilder(ObjectManagerInterface::class)
33+
->getMockForAbstractClass();
34+
ObjectManager::setInstance($objectManagerMock);
4035
}
41-
ObjectManager::setInstance($this->objectManager);
4236
}
4337
}

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

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

0 commit comments

Comments
 (0)