21
21
use Composer \Config ;
22
22
use PHPUnit \Framework \MockObject \MockObject ;
23
23
use Composer \DependencyResolver \Pool ;
24
+ use Composer \Util \HttpDownloader ;
25
+ use Composer \Repository \RepositorySet ;
24
26
25
27
/**
26
28
* Test for Class Magento\ComposerDependencyVersionAuditPlugin\Plugin
@@ -87,20 +89,45 @@ class PluginTest extends TestCase
87
89
*/
88
90
private $ repositoryMock2 ;
89
91
92
+ /**
93
+ * @var HttpDownloader
94
+ */
95
+ private $ httpDownloader ;
96
+
97
+ /**
98
+ * @var MockObject
99
+ */
100
+ private $ repositorySetMock ;
101
+
90
102
91
103
/**#@+
92
104
* Package name constant for test
93
105
*/
94
- const PACKAGE_NAME = 'foo ' ;
106
+ const PACKAGE_NAME = 'foo/some-test-package ' ;
95
107
96
108
/**
97
109
* Initialize Dependencies
98
110
*/
99
111
protected function setUp (): void
100
112
{
113
+ $ composerMajorVersion = (int )explode ('. ' , Composer::VERSION )[0 ];
101
114
$ this ->io = new NullIO ();
102
115
$ this ->config = Factory::createConfig ($ this ->io );
103
- $ this ->repositoryManager = new RepositoryManager ($ this ->io , $ this ->config );
116
+
117
+ if ($ composerMajorVersion === 1 ) {
118
+ $ this ->repositoryManager = new RepositoryManager ($ this ->io , $ this ->config );
119
+ $ this ->poolMock = $ this ->getMockBuilder (Pool::class)
120
+ ->disableOriginalConstructor ()
121
+ ->onlyMethods (['addRepository ' ])
122
+ ->getMock ();
123
+ } elseif ($ composerMajorVersion === 2 ) {
124
+ $ this ->httpDownloader = new HttpDownloader ($ this ->io , $ this ->config );
125
+ $ this ->repositoryManager = new RepositoryManager ($ this ->io , $ this ->config , $ this ->httpDownloader );
126
+ $ this ->repositorySetMock = $ this ->getMockBuilder (RepositorySet::class)
127
+ ->disableOriginalConstructor ()
128
+ ->onlyMethods (['addRepository ' ])
129
+ ->getMock ();
130
+ }
104
131
105
132
$ this ->eventMock = $ this ->getMockBuilder (PackageEvent::class)
106
133
->onlyMethods (['getOperation ' , 'getComposer ' ])
@@ -121,11 +148,6 @@ protected function setUp(): void
121
148
->onlyMethods (['getPackage ' ])
122
149
->getMock ();
123
150
124
- $ this ->poolMock = $ this ->getMockBuilder (Pool::class)
125
- ->disableOriginalConstructor ()
126
- ->onlyMethods (['addRepository ' ])
127
- ->getMock ();
128
-
129
151
$ this ->versionSelectorMock = $ this ->getMockBuilder (Version::class)
130
152
->disableOriginalConstructor ()
131
153
->onlyMethods (['findBestCandidate ' ])
0 commit comments