Skip to content

Commit 498822d

Browse files
authored
Merge pull request #4 from magento-commerce/AC-1183
AC-1183: Making unit tests compatible with Composer 2.
2 parents 858461c + 1d74deb commit 498822d

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/composer-dependency-version-audit-plugin",
33
"type": "composer-plugin",
44
"description": "Validating packages through a composer plugin",
5-
"version": "0.1.1",
5+
"version": "0.1.2",
66
"license": [
77
"OSL-3.0"
88
],

tests/Unit/Magento/ComposerDependencyVersionAuditPlugin/PluginTest.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Composer\Config;
2222
use PHPUnit\Framework\MockObject\MockObject;
2323
use Composer\DependencyResolver\Pool;
24+
use Composer\Util\HttpDownloader;
25+
use Composer\Repository\RepositorySet;
2426

2527
/**
2628
* Test for Class Magento\ComposerDependencyVersionAuditPlugin\Plugin
@@ -87,20 +89,45 @@ class PluginTest extends TestCase
8789
*/
8890
private $repositoryMock2;
8991

92+
/**
93+
* @var HttpDownloader
94+
*/
95+
private $httpDownloader;
96+
97+
/**
98+
* @var MockObject
99+
*/
100+
private $repositorySetMock;
101+
90102

91103
/**#@+
92104
* Package name constant for test
93105
*/
94-
const PACKAGE_NAME = 'foo';
106+
const PACKAGE_NAME = 'foo/some-test-package';
95107

96108
/**
97109
* Initialize Dependencies
98110
*/
99111
protected function setUp(): void
100112
{
113+
$composerMajorVersion = (int)explode('.', Composer::VERSION)[0];
101114
$this->io = new NullIO();
102115
$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+
}
104131

105132
$this->eventMock = $this->getMockBuilder(PackageEvent::class)
106133
->onlyMethods(['getOperation', 'getComposer'])
@@ -121,11 +148,6 @@ protected function setUp(): void
121148
->onlyMethods(['getPackage'])
122149
->getMock();
123150

124-
$this->poolMock = $this->getMockBuilder(Pool::class)
125-
->disableOriginalConstructor()
126-
->onlyMethods(['addRepository'])
127-
->getMock();
128-
129151
$this->versionSelectorMock = $this->getMockBuilder(Version::class)
130152
->disableOriginalConstructor()
131153
->onlyMethods(['findBestCandidate'])

0 commit comments

Comments
 (0)