1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
<?php declare(strict_types=1);
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\Command;
use Composer\Test\TestCase;
use LogicException;
use PHPUnit\Framework\Attributes\DataProvider;
class CheckPlatformReqsCommandTest extends TestCase
{
/**
* @param array<mixed> $composerJson
* @param array<mixed> $command
*/
#[DataProvider('caseProvider')]
public function testPlatformReqsAreSatisfied(
array $composerJson,
array $command,
string $expected,
bool $lock = true
): void {
$this->initTempComposer($composerJson);
$packages = [
self::getPackage('ext-foobar', '2.3.4'),
];
$devPackages = [
self::getPackage('ext-barbaz', '2.3.4.5')
];
$this->createInstalledJson($packages, $devPackages);
if ($lock) {
$this->createComposerLock($packages, $devPackages);
}
$appTester = $this->getApplicationTester();
$appTester->run(array_merge(['command' => 'check-platform-reqs'], $command));
$appTester->assertCommandIsSuccessful();
self::assertSame(trim($expected), trim($appTester->getDisplay(true)));
}
public function testExceptionThrownIfNoLockfileFound(): void
{
$this->expectException(LogicException::class);
$this->expectExceptionMessage("No lockfile found. Unable to read locked packages");
$this->initTempComposer([]);
$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'check-platform-reqs']);
}
public static function caseProvider(): \Generator
{
yield 'Disables checking of require-dev packages requirements.' => [
[
'require' => [
'ext-foobar' => '^2.0',
],
'require-dev' => [
'ext-barbaz' => '~4.0',
]
],
['--no-dev' => true],
'Checking non-dev platform requirements for packages in the vendor dir
ext-foobar 2.3.4 success'
];
yield 'Checks requirements only from the lock file, not from installed packages.' => [
[
'require' => [
'ext-foobar' => '^2.3',
],
'require-dev' => [
'ext-barbaz' => '~2.0',
]
],
['--lock' => true],
"Checking platform requirements using the lock file\next-barbaz 2.3.4.5 success \next-foobar 2.3.4 success"
];
}
public function testFailedPlatformRequirement(): void
{
$this->initTempComposer([
'require' => [
'ext-foobar' => '^0.3'
],
'require-dev' => [
'ext-barbaz' => '^2.3'
]
]);
$packages = [
self::getPackage('ext-foobar', '2.3.4'),
];
$devPackages = [
self::getPackage('ext-barbaz', '2.3.4.5')
];
$this->createInstalledJson($packages, $devPackages);
$this->createComposerLock($packages, $devPackages);
$appTester = $this->getApplicationTester();
$appTester->run(['command' => 'check-platform-reqs', '--format' => 'json']);
$expected = 'Checking platform requirements for packages in the vendor dir
[
{
"name": "ext-barbaz",
"version": "2.3.4.5",
"status": "success",
"failed_requirement": null,
"provider": null
},
{
"name": "ext-foobar",
"version": "2.3.4",
"status": "failed",
"failed_requirement": {
"source": "__root__",
"type": "requires",
"target": "ext-foobar",
"constraint": "^0.3"
},
"provider": null
}
]';
self::assertSame(trim($expected), trim($appTester->getDisplay(true)));
}
}
|