File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
lib/internal/Magento/Framework/TestFramework/Unit/Listener Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 11
11
use PHPUnit \Framework \TestCase ;
12
12
use PHPUnit \Framework \TestListener ;
13
13
use PHPUnit \Framework \TestListenerDefaultImplementation ;
14
+ use Magento \Framework \TestFramework \Unit \Listener \ReplaceObjectManager \TestProvidesServiceInterface ;
14
15
15
16
/**
16
17
* The event listener which instantiates ObjectManager before test run
@@ -36,6 +37,12 @@ public function startTest(Test $test): void
36
37
$ objectManagerMock = $ test ->getMockBuilder (ObjectManagerInterface::class)
37
38
->getMockForAbstractClass ();
38
39
$ createMockCallback = function ($ type ) use ($ test ) {
40
+ if ($ test instanceof TestProvidesServiceInterface) {
41
+ $ serviceObject = $ test ->getServiceForObjectManager ($ type );
42
+ if ($ serviceObject ) {
43
+ return $ serviceObject ;
44
+ }
45
+ }
39
46
return $ test ->getMockBuilder ($ type )
40
47
->disableOriginalConstructor ()
41
48
->getMockForAbstractClass ();
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments