Skip to content

Commit c81d848

Browse files
authored
Merge pull request #490 from php/1.3.x
Merge up 1.3 to 1.4 - forwards compat for download-url-method lists
2 parents 4f4ad56 + a8bf21c commit c81d848

4 files changed

Lines changed: 58 additions & 3 deletions

File tree

phpstan-baseline.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,18 @@ parameters:
414414
count: 1
415415
path: test/unit/ComposerIntegration/VendorCleanupTest.php
416416

417+
-
418+
message: '#^Parameter \#1 \$phpExt of method Composer\\Package\\Package\:\:setPhpExt\(\) expects array\{extension\-name\?\: string, priority\?\: int, support\-zts\?\: bool, support\-nts\?\: bool, build\-path\?\: string\|null, download\-url\-method\?\: string, os\-families\?\: non\-empty\-list\<non\-empty\-string\>, os\-families\-exclude\?\: non\-empty\-list\<non\-empty\-string\>, \.\.\.\}\|null, array\{download\-url\-method\: array\{''composer\-default''\}\} given\.$#'
419+
identifier: argument.type
420+
count: 1
421+
path: test/unit/DependencyResolver/PackageTest.php
422+
423+
-
424+
message: '#^Parameter \#1 \$phpExt of method Composer\\Package\\Package\:\:setPhpExt\(\) expects array\{extension\-name\?\: string, priority\?\: int, support\-zts\?\: bool, support\-nts\?\: bool, build\-path\?\: string\|null, download\-url\-method\?\: string, os\-families\?\: non\-empty\-list\<non\-empty\-string\>, os\-families\-exclude\?\: non\-empty\-list\<non\-empty\-string\>, \.\.\.\}\|null, array\{download\-url\-method\: array\{''pre\-packaged\-source'', ''composer\-default''\}\} given\.$#'
425+
identifier: argument.type
426+
count: 1
427+
path: test/unit/DependencyResolver/PackageTest.php
428+
417429
-
418430
message: '#^Parameter \#2 \$extractedSourcePath of static method Php\\Pie\\Downloading\\DownloadedPackage\:\:fromPackageAndExtractedPath\(\) expects string, string\|false given\.$#'
419431
identifier: argument.type

src/DependencyResolver/Package.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
use function array_key_exists;
1717
use function array_map;
1818
use function array_slice;
19+
use function count;
1920
use function explode;
2021
use function implode;
22+
use function is_array;
2123
use function parse_url;
2224
use function str_contains;
2325
use function str_starts_with;
@@ -89,7 +91,17 @@ public static function fromComposerCompletePackage(CompletePackageInterface $com
8991
$package->priority = $phpExtOptions['priority'] ?? 80;
9092

9193
if ($phpExtOptions !== null && array_key_exists('download-url-method', $phpExtOptions)) {
92-
$package->downloadUrlMethod = DownloadUrlMethod::tryFrom($phpExtOptions['download-url-method']);
94+
/** @var string|list<string> $method */
95+
$method = $phpExtOptions['download-url-method'];
96+
if (is_array($method)) {
97+
if (count($method) !== 1) {
98+
throw new InvalidArgumentException('This extension requires a newer version of PIE. Multiple download-url-methods are not supported until PIE 1.4.0.');
99+
}
100+
101+
$method = $method[0];
102+
}
103+
104+
$package->downloadUrlMethod = DownloadUrlMethod::tryFrom($method);
93105
}
94106

95107
return $package;

test/unit/DependencyResolver/PackageTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Composer\Package\CompletePackageInterface;
99
use InvalidArgumentException;
1010
use Php\Pie\DependencyResolver\Package;
11+
use Php\Pie\Downloading\DownloadUrlMethod;
1112
use Php\Pie\ExtensionName;
1213
use Php\Pie\ExtensionType;
1314
use Php\Pie\Platform\OperatingSystemFamily;
@@ -146,4 +147,34 @@ public function testFromComposerCompletePackageWithBuildPath(): void
146147
self::assertSame('vendor/foo:1.2.3', $package->prettyNameAndVersion());
147148
self::assertSame('some/subdirectory/path/', $package->buildPath());
148149
}
150+
151+
public function testDownloadUrlMethodWithStringHasValidDownloadUrlMethod(): void
152+
{
153+
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
154+
$composerCompletePackage->setPhpExt(['download-url-method' => 'composer-default']);
155+
156+
$package = Package::fromComposerCompletePackage($composerCompletePackage);
157+
158+
self::assertSame(DownloadUrlMethod::ComposerDefaultDownload, $package->downloadUrlMethod());
159+
}
160+
161+
public function testDownloadUrlMethodWithSingleItemListHasValidDownloadUrlMethod(): void
162+
{
163+
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
164+
$composerCompletePackage->setPhpExt(['download-url-method' => ['composer-default']]);
165+
166+
$package = Package::fromComposerCompletePackage($composerCompletePackage);
167+
168+
self::assertSame(DownloadUrlMethod::ComposerDefaultDownload, $package->downloadUrlMethod());
169+
}
170+
171+
public function testDownloadUrlMethodWithMultiItemListIsNotYetSupported(): void
172+
{
173+
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
174+
$composerCompletePackage->setPhpExt(['download-url-method' => ['pre-packaged-source', 'composer-default']]);
175+
176+
$this->expectException(InvalidArgumentException::class);
177+
$this->expectExceptionMessage('This extension requires a newer version of PIE. Multiple download-url-methods are not supported until PIE 1.4.0.');
178+
Package::fromComposerCompletePackage($composerCompletePackage);
179+
}
149180
}

test/unit/Platform/TargetPhp/PhpBinaryPathTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
use const PHP_MAJOR_VERSION;
5252
use const PHP_MINOR_VERSION;
5353
use const PHP_OS_FAMILY;
54-
use const PHP_VERSION;
54+
use const PHP_RELEASE_VERSION;
5555

5656
#[CoversClass(PhpBinaryPath::class)]
5757
final class PhpBinaryPathTest extends TestCase
@@ -117,7 +117,7 @@ public function testVersionFromCurrentProcess(): void
117117
$phpBinary = PhpBinaryPath::fromCurrentProcess();
118118

119119
self::assertSame(
120-
PHP_VERSION,
120+
PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION,
121121
$phpBinary->version(),
122122
);
123123

0 commit comments

Comments
 (0)