Skip to content

Commit 1f54cd1

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'origin/MAGETWO-69240' into SEGFAULT_BANNERS_PR
2 parents 4f11992 + 7915533 commit 1f54cd1

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

app/code/Magento/Review/Test/Unit/Model/ResourceModel/Review/Product/CollectionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
3434

3535
protected function setUp()
3636
{
37+
$this->markTestSkipped('MAGETWO-59234: Code under the test depends on a virtual type which cannot be mocked.');
38+
3739
$attribute = $this->getMock(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class, null, [], '', false);
3840
$eavConfig = $this->getMock(\Magento\Eav\Model\Config::class, ['getAttribute'], [], '', false);
3941
$eavConfig->expects($this->any())->method('getAttribute')->will($this->returnValue($attribute));

dev/tests/unit/phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
</exclude>
3939
</whitelist>
4040
</filter>
41+
<listeners>
42+
<listener class="Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager"/>
43+
</listeners>
4144
<logging>
4245
<!--coverage_html_placeholder
4346
<log type="coverage-html" target="{{coverage_dir}}/test-reports/coverage" charset="UTF-8" yui="true" highlight="true"/>
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\TestFramework\Unit\Listener;
8+
9+
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\ObjectManagerInterface;
12+
13+
/**
14+
* The event listener which instantiates ObjectManager before test run
15+
*/
16+
class ReplaceObjectManager extends \PHPUnit_Framework_BaseTestListener
17+
{
18+
/**
19+
* Replaces ObjectManager before run for each test
20+
*
21+
* Replace existing instance of the Application's ObjectManager with the mock.
22+
*
23+
* This avoids the issue with a not initialized ObjectManager
24+
* and makes working with ObjectManager predictable as it always contains clear mock for each test
25+
*
26+
* @param \PHPUnit_Framework_Test $test
27+
* @return void
28+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
29+
*/
30+
public function startTest(\PHPUnit_Framework_Test $test)
31+
{
32+
if ($test instanceof \PHPUnit_Framework_TestCase) {
33+
$objectManagerMock = $test->getMockBuilder(ObjectManagerInterface::class)
34+
->getMockForAbstractClass();
35+
$createMockCallback = function ($type) use ($test) {
36+
return $test->getMockBuilder($type)
37+
->disableOriginalConstructor()
38+
->getMockForAbstractClass();
39+
};
40+
$objectManagerMock->method('create')->willReturnCallback($createMockCallback);
41+
$objectManagerMock->method('get')->willReturnCallback($createMockCallback);
42+
ObjectManager::setInstance($objectManagerMock);
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)