Skip to content

Commit dfc60a4

Browse files
ACPT-987
fixes for unit tests
1 parent 6b11e6f commit dfc60a4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPUnit\Framework\TestCase;
1212
use PHPUnit\Framework\TestListener;
1313
use PHPUnit\Framework\TestListenerDefaultImplementation;
14+
use Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager\TestProvidesServiceInterface;
1415

1516
/**
1617
* The event listener which instantiates ObjectManager before test run
@@ -36,6 +37,12 @@ public function startTest(Test $test): void
3637
$objectManagerMock = $test->getMockBuilder(ObjectManagerInterface::class)
3738
->getMockForAbstractClass();
3839
$createMockCallback = function ($type) use ($test) {
40+
if ($test instanceof TestProvidesServiceInterface) {
41+
$serviceObject = $test->getServiceForObjectManager($type);
42+
if ($serviceObject) {
43+
return $serviceObject;
44+
}
45+
}
3946
return $test->getMockBuilder($type)
4047
->disableOriginalConstructor()
4148
->getMockForAbstractClass();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager;
7+
8+
interface TestProvidesServiceInterface
9+
{
10+
/**
11+
* Gets a service object from a test to use by the mock object manager
12+
*
13+
* @param string $type
14+
* @return object|null
15+
*/
16+
public function getServiceForObjectManager(string $type) : ?object;
17+
}

0 commit comments

Comments
 (0)