mirror of
https://github.com/php/pie.git
synced 2026-03-23 23:12:17 +01:00
436: added a bunch of tests for pre-built binaries
This commit is contained in:
@@ -10,6 +10,14 @@ use function sprintf;
|
||||
|
||||
class ExtensionBinaryNotFound extends RuntimeException
|
||||
{
|
||||
public static function fromPrePackagedBinary(string $expectedBinaryName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
'Expected pre-packaged binary does not exist: %s',
|
||||
$expectedBinaryName,
|
||||
));
|
||||
}
|
||||
|
||||
public static function fromExpectedBinary(string $expectedBinaryName): self
|
||||
{
|
||||
return new self(sprintf(
|
||||
|
||||
@@ -56,7 +56,7 @@ final class UnixBuild implements Build
|
||||
$expectedSoFile = $downloadedPackage->extractedSourcePath . '/' . $downloadedPackage->package->extensionName()->name() . '.so';
|
||||
|
||||
if (! file_exists($expectedSoFile)) {
|
||||
throw ExtensionBinaryNotFound::fromExpectedBinary($expectedSoFile);
|
||||
throw ExtensionBinaryNotFound::fromPrePackagedBinary($expectedSoFile);
|
||||
}
|
||||
|
||||
$io->write(sprintf(
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Php\Pie\ComposerIntegration\Listeners;
|
||||
|
||||
use Php\Pie\DependencyResolver\Package;
|
||||
use Php\Pie\Downloading\DownloadUrlMethod;
|
||||
use RuntimeException;
|
||||
|
||||
use function array_key_first;
|
||||
use function count;
|
||||
use function sprintf;
|
||||
|
||||
use const PHP_EOL;
|
||||
|
||||
class CouldNotDetermineDownloadUrlMethod extends RuntimeException
|
||||
{
|
||||
/**
|
||||
* @param non-empty-list<DownloadUrlMethod> $downloadMethods
|
||||
* @param array<string, string> $failureReasons
|
||||
*/
|
||||
public static function fromDownloadUrlMethods(Package $piePackage, array $downloadMethods, array $failureReasons): self
|
||||
{
|
||||
$message = sprintf('Could not download %s', $piePackage->name());
|
||||
|
||||
if (count($downloadMethods) === 1) {
|
||||
$first = array_key_first($downloadMethods);
|
||||
$message .= sprintf(' using %s method: %s', $downloadMethods[$first]->value, $failureReasons[$downloadMethods[$first]->value] ?? '(unknown failure)');
|
||||
|
||||
return new self($message);
|
||||
}
|
||||
|
||||
$message .= ' using the following methods:' . PHP_EOL;
|
||||
|
||||
foreach ($downloadMethods as $downloadMethod) {
|
||||
$message .= sprintf(' - %s: %s%s', $downloadMethod->value, $failureReasons[$downloadMethod->value] ?? '(unknown failure)', PHP_EOL);
|
||||
}
|
||||
|
||||
return new self($message);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@ use Php\Pie\DependencyResolver\Package;
|
||||
use Php\Pie\Downloading\DownloadUrlMethod;
|
||||
use Php\Pie\Downloading\PackageReleaseAssets;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
use function array_walk;
|
||||
@@ -76,9 +75,10 @@ class OverrideDownloadUrlInstallListener
|
||||
$downloadUrlMethods = DownloadUrlMethod::possibleDownloadUrlMethodsForPackage($piePackage, $targetPlatform);
|
||||
|
||||
$selectedDownloadUrlMethod = null;
|
||||
$downloadMethodFailures = [];
|
||||
|
||||
foreach ($downloadUrlMethods as $downloadUrlMethod) {
|
||||
$this->io->write('Trying: ' . $downloadUrlMethod->value); // @todo 436 verbosity
|
||||
$this->io->write('Trying to download using: ' . $downloadUrlMethod->value, verbosity: IOInterface::VERY_VERBOSE);
|
||||
|
||||
// Exit early if we should just use Composer's normal download
|
||||
if ($downloadUrlMethod === DownloadUrlMethod::ComposerDefaultDownload) {
|
||||
@@ -89,12 +89,14 @@ class OverrideDownloadUrlInstallListener
|
||||
try {
|
||||
$possibleAssetNames = $downloadUrlMethod->possibleAssetNames($piePackage, $targetPlatform);
|
||||
} catch (Throwable $t) {
|
||||
$this->io->write('Failed fetching asset names [' . $downloadUrlMethod->value . ']: ' . $t->getMessage()); // @todo 436 verbosity
|
||||
$downloadMethodFailures[$downloadUrlMethod->value] = $t->getMessage();
|
||||
$this->io->write('Failed fetching asset names [' . $downloadUrlMethod->value . ']: ' . $t->getMessage(), verbosity: IOInterface::VERBOSE);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($possibleAssetNames === null) {
|
||||
$this->io->write('Failed fetching asset names [' . $downloadUrlMethod->value . ']: No asset names'); // @todo 436 verbosity
|
||||
$downloadMethodFailures[$downloadUrlMethod->value] = 'No asset names';
|
||||
$this->io->write('Failed fetching asset names [' . $downloadUrlMethod->value . ']: No asset names', verbosity: IOInterface::VERBOSE);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -110,7 +112,8 @@ class OverrideDownloadUrlInstallListener
|
||||
$possibleAssetNames,
|
||||
);
|
||||
} catch (Throwable $t) {
|
||||
$this->io->write('Failed locating asset [' . $downloadUrlMethod->value . ']: ' . $t->getMessage()); // @todo 436 verbosity
|
||||
$downloadMethodFailures[$downloadUrlMethod->value] = $t->getMessage();
|
||||
$this->io->write('Failed locating asset [' . $downloadUrlMethod->value . ']: ' . $t->getMessage(), verbosity: IOInterface::VERBOSE);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -126,11 +129,11 @@ class OverrideDownloadUrlInstallListener
|
||||
}
|
||||
|
||||
if ($selectedDownloadUrlMethod === null) {
|
||||
throw new RuntimeException('No download method could be found for ' . $piePackage->name()); // @todo 436 improve message, will need to give more info!
|
||||
throw CouldNotDetermineDownloadUrlMethod::fromDownloadUrlMethods($piePackage, $downloadUrlMethods, $downloadMethodFailures);
|
||||
}
|
||||
|
||||
$selectedDownloadUrlMethod->writeToComposerPackage($composerPackage);
|
||||
$this->io->write('<info>FINALLY SETTLED on using download URL method: ' . $selectedDownloadUrlMethod->value . '</info>'); // @todo 436 verbosity
|
||||
$this->io->write('<info>Selected download URL method: ' . $selectedDownloadUrlMethod->value . '</info>', verbosity: IOInterface::VERBOSE);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ use Webmozart\Assert\Assert;
|
||||
|
||||
use function array_unshift;
|
||||
use function file_exists;
|
||||
use function implode;
|
||||
use function is_writable;
|
||||
use function sprintf;
|
||||
|
||||
@@ -73,6 +74,8 @@ final class UnixInstall implements Install
|
||||
array_unshift($installCommand, Sudo::find());
|
||||
}
|
||||
|
||||
$io->write(sprintf('<info>Install command is: %s</info>', implode(' ', $installCommand)), verbosity: IOInterface::VERY_VERBOSE);
|
||||
|
||||
$makeInstallOutput = Process::run(
|
||||
$installCommand,
|
||||
$downloadedPackage->extractedSourcePath,
|
||||
|
||||
8
test/assets/fake-ldd/glibc/ldd
Executable file
8
test/assets/fake-ldd/glibc/ldd
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo " linux-vdso.so.1 (0x000078fecccd6000)
|
||||
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x000078feccc57000)
|
||||
libcap.so.2 => /lib/x86_64-linux-gnu/libcap.so.2 (0x000078feccc49000)
|
||||
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x000078fecca00000)
|
||||
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x000078fecc941000)
|
||||
/lib64/ld-linux-x86-64.so.2 (0x000078fecccd8000)"
|
||||
4
test/assets/fake-ldd/musl/ldd
Executable file
4
test/assets/fake-ldd/musl/ldd
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo " /lib/ld-musl-x86_64.so.1 (0x7146f93b1000)
|
||||
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7146f93b1000)"
|
||||
@@ -28,6 +28,8 @@ final class UnixBuildTest extends TestCase
|
||||
{
|
||||
private const COMPOSER_PACKAGE_EXTRA_KEY = 'download-url-method';
|
||||
private const TEST_EXTENSION_PATH = __DIR__ . '/../../assets/pie_test_ext';
|
||||
private const TEST_PREBUILT_PATH_VALID = __DIR__ . '/../../assets/pre-packaged-binary-examples/valid';
|
||||
private const TEST_PREBUILT_PATH_INVALID = __DIR__ . '/../../assets/pre-packaged-binary-examples/invalid';
|
||||
|
||||
public function testUnixSourceBuildCanBuildExtension(): void
|
||||
{
|
||||
@@ -178,12 +180,73 @@ final class UnixBuildTest extends TestCase
|
||||
|
||||
public function testUnixBinaryBuildThrowsErrorWhenBinaryFileNotFound(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
if (Platform::isWindows()) {
|
||||
self::markTestSkipped('Unix build test cannot be run on Windows');
|
||||
}
|
||||
|
||||
$output = new BufferIO();
|
||||
|
||||
$composerPackage = $this->createMock(CompletePackageInterface::class);
|
||||
$composerPackage->method('getPrettyName')->willReturn('myvendor/pie_test_ext');
|
||||
$composerPackage->method('getPrettyVersion')->willReturn('0.1.0');
|
||||
$composerPackage->method('getType')->willReturn('php-ext');
|
||||
$composerPackage
|
||||
->method('getExtra')
|
||||
->willReturn([self::COMPOSER_PACKAGE_EXTRA_KEY => DownloadUrlMethod::PrePackagedBinary->value]);
|
||||
|
||||
$downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath(
|
||||
Package::fromComposerCompletePackage($composerPackage),
|
||||
self::TEST_PREBUILT_PATH_INVALID,
|
||||
);
|
||||
|
||||
$targetPlatform = TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null);
|
||||
$unixBuilder = new UnixBuild();
|
||||
|
||||
$this->expectException(ExtensionBinaryNotFound::class);
|
||||
$this->expectExceptionMessage('Expected pre-packaged binary does not exist');
|
||||
$unixBuilder->__invoke(
|
||||
$downloadedPackage,
|
||||
$targetPlatform,
|
||||
['--enable-pie_test_ext'],
|
||||
$output,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
public function testUnixBinaryBuildReturnsBinaryFile(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
if (Platform::isWindows()) {
|
||||
self::markTestSkipped('Unix build test cannot be run on Windows');
|
||||
}
|
||||
|
||||
$output = new BufferIO();
|
||||
|
||||
$composerPackage = $this->createMock(CompletePackageInterface::class);
|
||||
$composerPackage->method('getPrettyName')->willReturn('myvendor/pie_test_ext');
|
||||
$composerPackage->method('getPrettyVersion')->willReturn('0.1.0');
|
||||
$composerPackage->method('getType')->willReturn('php-ext');
|
||||
$composerPackage
|
||||
->method('getExtra')
|
||||
->willReturn([self::COMPOSER_PACKAGE_EXTRA_KEY => DownloadUrlMethod::PrePackagedBinary->value]);
|
||||
|
||||
$downloadedPackage = DownloadedPackage::fromPackageAndExtractedPath(
|
||||
Package::fromComposerCompletePackage($composerPackage),
|
||||
self::TEST_PREBUILT_PATH_VALID,
|
||||
);
|
||||
|
||||
$targetPlatform = TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null);
|
||||
$unixBuilder = new UnixBuild();
|
||||
|
||||
$binaryFile = $unixBuilder->__invoke(
|
||||
$downloadedPackage,
|
||||
$targetPlatform,
|
||||
['--enable-pie_test_ext'],
|
||||
$output,
|
||||
null,
|
||||
);
|
||||
|
||||
self::assertSame('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', $binaryFile->checksum);
|
||||
self::assertStringEndsWith('pre-packaged-binary-examples/valid/pie_test_ext.so', $binaryFile->filePath);
|
||||
}
|
||||
|
||||
public function testCleanupDoesNotCleanWhenConfigureIsMissing(): void
|
||||
|
||||
@@ -13,6 +13,7 @@ use Php\Pie\Downloading\DownloadedPackage;
|
||||
use Php\Pie\Downloading\DownloadUrlMethod;
|
||||
use Php\Pie\ExtensionName;
|
||||
use Php\Pie\ExtensionType;
|
||||
use Php\Pie\File\BinaryFile;
|
||||
use Php\Pie\Installing\Ini\PickBestSetupIniApproach;
|
||||
use Php\Pie\Installing\SetupIniFile;
|
||||
use Php\Pie\Installing\UnixInstall;
|
||||
@@ -31,12 +32,18 @@ use function assert;
|
||||
use function file_exists;
|
||||
use function is_executable;
|
||||
use function is_writable;
|
||||
use function mkdir;
|
||||
use function rename;
|
||||
use function unlink;
|
||||
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
||||
#[CoversClass(UnixInstall::class)]
|
||||
final class UnixInstallTest extends TestCase
|
||||
{
|
||||
private const COMPOSER_PACKAGE_EXTRA_KEY = 'download-url-method';
|
||||
private const TEST_EXTENSION_PATH = __DIR__ . '/../../assets/pie_test_ext';
|
||||
private const TEST_PREBUILT_PATH = __DIR__ . '/../../assets/pre-packaged-binary-examples/install';
|
||||
|
||||
/** @return array<string, array{0: non-empty-string}> */
|
||||
public static function phpPathProvider(): array
|
||||
@@ -131,8 +138,88 @@ final class UnixInstallTest extends TestCase
|
||||
(new Process(['phpize', '--clean'], $downloadedPackage->extractedSourcePath))->mustRun();
|
||||
}
|
||||
|
||||
public function testUnixInstallCanInstallPrePackagedBinary(): void
|
||||
#[DataProvider('phpPathProvider')]
|
||||
public function testUnixInstallCanInstallPrePackagedBinary(string $phpConfig): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
assert($phpConfig !== '');
|
||||
if (Platform::isWindows()) {
|
||||
self::markTestSkipped('Unix build test cannot be run on Windows');
|
||||
}
|
||||
|
||||
$output = new BufferIO();
|
||||
$targetPlatform = TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromPhpConfigExecutable($phpConfig), null);
|
||||
$extensionPath = $targetPlatform->phpBinaryPath->extensionPath();
|
||||
|
||||
// First build it (otherwise the test assets would need to have a binary for every test platform...)
|
||||
$composerPackage = $this->createMock(CompletePackageInterface::class);
|
||||
$composerPackage
|
||||
->method('getExtra')
|
||||
->willReturn([self::COMPOSER_PACKAGE_EXTRA_KEY => DownloadUrlMethod::ComposerDefaultDownload->value]);
|
||||
|
||||
$built = (new UnixBuild())->__invoke(
|
||||
DownloadedPackage::fromPackageAndExtractedPath(
|
||||
new Package(
|
||||
$composerPackage,
|
||||
ExtensionType::PhpModule,
|
||||
ExtensionName::normaliseFromString('pie_test_ext'),
|
||||
'pie_test_ext',
|
||||
'0.1.0',
|
||||
null,
|
||||
),
|
||||
self::TEST_EXTENSION_PATH,
|
||||
),
|
||||
$targetPlatform,
|
||||
['--enable-pie_test_ext'],
|
||||
$output,
|
||||
null,
|
||||
);
|
||||
|
||||
/**
|
||||
* Move the built .so into a new path; this simulates a pre-packaged binary, which would not have Makefile etc
|
||||
* so this ensures we're not accidentally relying on any build mechanism (`make install` or otherwise)
|
||||
*/
|
||||
mkdir(self::TEST_PREBUILT_PATH, 0777, true);
|
||||
$prebuiltBinaryFilePath = self::TEST_PREBUILT_PATH . DIRECTORY_SEPARATOR . 'pie_test_ext.so';
|
||||
rename($built->filePath, $prebuiltBinaryFilePath);
|
||||
|
||||
$prebuiltBinaryFile = BinaryFile::fromFileWithSha256Checksum($prebuiltBinaryFilePath);
|
||||
|
||||
$composerPackage = $this->createMock(CompletePackageInterface::class);
|
||||
$composerPackage
|
||||
->method('getExtra')
|
||||
->willReturn([self::COMPOSER_PACKAGE_EXTRA_KEY => DownloadUrlMethod::PrePackagedBinary->value]);
|
||||
|
||||
$installedSharedObject = (new UnixInstall(new SetupIniFile(new PickBestSetupIniApproach([]))))->__invoke(
|
||||
DownloadedPackage::fromPackageAndExtractedPath(
|
||||
new Package(
|
||||
$composerPackage,
|
||||
ExtensionType::PhpModule,
|
||||
ExtensionName::normaliseFromString('pie_test_ext'),
|
||||
'pie_test_ext',
|
||||
'0.1.0',
|
||||
null,
|
||||
),
|
||||
self::TEST_PREBUILT_PATH,
|
||||
),
|
||||
$targetPlatform,
|
||||
$prebuiltBinaryFile,
|
||||
$output,
|
||||
true,
|
||||
);
|
||||
$outputString = $output->getOutput();
|
||||
|
||||
self::assertStringContainsString('Install complete: ' . $extensionPath . '/pie_test_ext.so', $outputString);
|
||||
self::assertStringContainsString('You must now add "extension=pie_test_ext" to your php.ini', $outputString);
|
||||
|
||||
self::assertSame($extensionPath . '/pie_test_ext.so', $installedSharedObject->filePath);
|
||||
self::assertFileExists($installedSharedObject->filePath);
|
||||
|
||||
$rmCommand = ['rm', $installedSharedObject->filePath];
|
||||
if (! is_writable($installedSharedObject->filePath)) {
|
||||
array_unshift($rmCommand, 'sudo');
|
||||
}
|
||||
|
||||
(new Process($rmCommand))->mustRun();
|
||||
unlink($prebuiltBinaryFile->filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Php\PieUnitTest\ComposerIntegration\Listeners;
|
||||
|
||||
use Composer\Package\CompletePackageInterface;
|
||||
use Php\Pie\ComposerIntegration\Listeners\CouldNotDetermineDownloadUrlMethod;
|
||||
use Php\Pie\DependencyResolver\Package;
|
||||
use Php\Pie\Downloading\DownloadUrlMethod;
|
||||
use Php\Pie\ExtensionName;
|
||||
use Php\Pie\ExtensionType;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[CoversClass(CouldNotDetermineDownloadUrlMethod::class)]
|
||||
final class CouldNotDetermineDownloadUrlMethodTest extends TestCase
|
||||
{
|
||||
public function testSingleDownloadUrlMethod(): void
|
||||
{
|
||||
$package = new Package(
|
||||
$this->createMock(CompletePackageInterface::class),
|
||||
ExtensionType::PhpModule,
|
||||
ExtensionName::normaliseFromString('foo'),
|
||||
'foo/foo',
|
||||
'1.2.3',
|
||||
null,
|
||||
);
|
||||
|
||||
$e = CouldNotDetermineDownloadUrlMethod::fromDownloadUrlMethods(
|
||||
$package,
|
||||
[DownloadUrlMethod::PrePackagedBinary],
|
||||
[DownloadUrlMethod::PrePackagedBinary->value => 'A bad thing happened downloading the binary'],
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'Could not download foo/foo using pre-packaged-binary method: A bad thing happened downloading the binary',
|
||||
$e->getMessage(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testMultipleDownloadUrlMethods(): void
|
||||
{
|
||||
$package = new Package(
|
||||
$this->createMock(CompletePackageInterface::class),
|
||||
ExtensionType::PhpModule,
|
||||
ExtensionName::normaliseFromString('foo'),
|
||||
'foo/foo',
|
||||
'1.2.3',
|
||||
null,
|
||||
);
|
||||
|
||||
$e = CouldNotDetermineDownloadUrlMethod::fromDownloadUrlMethods(
|
||||
$package,
|
||||
[
|
||||
DownloadUrlMethod::PrePackagedBinary,
|
||||
DownloadUrlMethod::PrePackagedSourceDownload,
|
||||
],
|
||||
[
|
||||
DownloadUrlMethod::PrePackagedBinary->value => 'A bad thing happened downloading the binary',
|
||||
DownloadUrlMethod::PrePackagedSourceDownload->value => 'Another bad thing happened downloading the source',
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
'Could not download foo/foo using the following methods:
|
||||
- pre-packaged-binary: A bad thing happened downloading the binary
|
||||
- pre-packaged-source: Another bad thing happened downloading the source
|
||||
',
|
||||
$e->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ use Composer\Installer\InstallerEvents;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\Package;
|
||||
use Php\Pie\ComposerIntegration\Listeners\CouldNotDetermineDownloadUrlMethod;
|
||||
use Php\Pie\ComposerIntegration\Listeners\OverrideDownloadUrlInstallListener;
|
||||
use Php\Pie\ComposerIntegration\PieComposerRequest;
|
||||
use Php\Pie\ComposerIntegration\PieOperation;
|
||||
@@ -501,6 +502,59 @@ final class OverrideDownloadUrlInstallListenerTest extends TestCase
|
||||
|
||||
public function testNoSelectedDownloadUrlMethodWillThrowException(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$composerPackage = new CompletePackage('foo/bar', '1.2.3.0', '1.2.3');
|
||||
$composerPackage->setDistType('zip');
|
||||
$composerPackage->setDistUrl('https://example.com/git-archive-zip-url');
|
||||
$composerPackage->setPhpExt([
|
||||
'extension-name' => 'foobar',
|
||||
'download-url-method' => ['pre-packaged-binary'],
|
||||
]);
|
||||
|
||||
$installerEvent = new InstallerEvent(
|
||||
InstallerEvents::PRE_OPERATIONS_EXEC,
|
||||
$this->composer,
|
||||
$this->io,
|
||||
false,
|
||||
true,
|
||||
new Transaction([], [$composerPackage]),
|
||||
);
|
||||
|
||||
$packageReleaseAssets = $this->createMock(PackageReleaseAssets::class);
|
||||
$packageReleaseAssets
|
||||
->expects(self::once())
|
||||
->method('findMatchingReleaseAssetUrl')
|
||||
->willThrowException(new CouldNotFindReleaseAsset('nope not found'));
|
||||
|
||||
$this->container
|
||||
->method('get')
|
||||
->with(PackageReleaseAssets::class)
|
||||
->willReturn($packageReleaseAssets);
|
||||
|
||||
$listener = new OverrideDownloadUrlInstallListener(
|
||||
$this->composer,
|
||||
$this->io,
|
||||
$this->container,
|
||||
new PieComposerRequest(
|
||||
$this->createMock(IOInterface::class),
|
||||
new TargetPlatform(
|
||||
OperatingSystem::NonWindows,
|
||||
OperatingSystemFamily::Linux,
|
||||
PhpBinaryPath::fromCurrentProcess(),
|
||||
Architecture::x86_64,
|
||||
ThreadSafetyMode::NonThreadSafe,
|
||||
1,
|
||||
WindowsCompiler::VC15,
|
||||
),
|
||||
new RequestedPackageAndVersion('foo/bar', '^1.1'),
|
||||
PieOperation::Install,
|
||||
[],
|
||||
null,
|
||||
false,
|
||||
),
|
||||
);
|
||||
|
||||
$this->expectException(CouldNotDetermineDownloadUrlMethod::class);
|
||||
$this->expectExceptionMessage('Could not download foo/bar using pre-packaged-binary method: nope not found');
|
||||
$listener($installerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,16 +180,30 @@ final class PackageTest extends TestCase
|
||||
|
||||
public function testFromComposerCompletePackageWithStringDownloadUrlMethod(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
|
||||
$composerCompletePackage->setPhpExt(['download-url-method' => 'pre-packaged-binary']);
|
||||
|
||||
self::assertSame(
|
||||
[DownloadUrlMethod::PrePackagedBinary],
|
||||
Package::fromComposerCompletePackage($composerCompletePackage)->supportedDownloadUrlMethods(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromComposerCompletePackageWithListDownloadUrlMethods(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
|
||||
$composerCompletePackage->setPhpExt(['download-url-method' => ['pre-packaged-binary', 'composer-default']]);
|
||||
|
||||
self::assertSame(
|
||||
[DownloadUrlMethod::PrePackagedBinary, DownloadUrlMethod::ComposerDefaultDownload],
|
||||
Package::fromComposerCompletePackage($composerCompletePackage)->supportedDownloadUrlMethods(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testFromComposerCompletePackageWithOmittedDownloadUrlMethod(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
self::assertNull(Package::fromComposerCompletePackage(
|
||||
new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3'),
|
||||
)->supportedDownloadUrlMethods());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Php\PieUnitTest\Downloading;
|
||||
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\CompletePackageInterface;
|
||||
use Php\Pie\DependencyResolver\Package;
|
||||
use Php\Pie\Downloading\DownloadedPackage;
|
||||
use Php\Pie\Downloading\DownloadUrlMethod;
|
||||
use Php\Pie\ExtensionName;
|
||||
use Php\Pie\ExtensionType;
|
||||
@@ -19,6 +21,7 @@ use Php\Pie\Platform\ThreadSafetyMode;
|
||||
use Php\Pie\Platform\WindowsCompiler;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ValueError;
|
||||
|
||||
use function array_key_first;
|
||||
|
||||
@@ -241,21 +244,36 @@ final class DownloadUrlMethodTest extends TestCase
|
||||
|
||||
public function testFromComposerPackageWhenPackageKeyWasDefined(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$composerPackage = new CompletePackage('foo/bar', '1.2.3.0', '1.2.3');
|
||||
DownloadUrlMethod::PrePackagedBinary->writeToComposerPackage($composerPackage);
|
||||
self::assertSame(DownloadUrlMethod::PrePackagedBinary, DownloadUrlMethod::fromComposerPackage($composerPackage));
|
||||
}
|
||||
|
||||
public function testFromComposerPackageWhenPackageKeyWasNotDefined(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$composerPackage = new CompletePackage('foo/bar', '1.2.3.0', '1.2.3');
|
||||
|
||||
$this->expectException(ValueError::class);
|
||||
DownloadUrlMethod::fromComposerPackage($composerPackage);
|
||||
}
|
||||
|
||||
public function testFromDownloadedPackage(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
}
|
||||
$composerPackage = new CompletePackage('foo/bar', '1.2.3.0', '1.2.3');
|
||||
DownloadUrlMethod::PrePackagedSourceDownload->writeToComposerPackage($composerPackage);
|
||||
|
||||
public function testWriteToComposerPackageStoresDownloadUrlMethod(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$downloaded = DownloadedPackage::fromPackageAndExtractedPath(
|
||||
new Package(
|
||||
$composerPackage,
|
||||
ExtensionType::PhpModule,
|
||||
ExtensionName::normaliseFromString('foo'),
|
||||
'foo/bar',
|
||||
'1.2.3',
|
||||
null,
|
||||
),
|
||||
'/path/to/extracted/source',
|
||||
);
|
||||
|
||||
self::assertSame(DownloadUrlMethod::PrePackagedSourceDownload, DownloadUrlMethod::fromDownloadedPackage($downloaded));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,18 +6,40 @@ namespace Php\PieUnitTest\Platform;
|
||||
|
||||
use Php\Pie\Platform\LibcFlavour;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use function getenv;
|
||||
use function putenv;
|
||||
use function realpath;
|
||||
|
||||
use const PATH_SEPARATOR;
|
||||
|
||||
#[CoversClass(LibcFlavour::class)]
|
||||
final class LibcFlavourTest extends TestCase
|
||||
{
|
||||
private const GLIBC_PATH = __DIR__ . '/../../assets/fake-ldd/glibc';
|
||||
private const MUSL_PATH = __DIR__ . '/../../assets/fake-ldd/musl';
|
||||
|
||||
#[RequiresOperatingSystemFamily('Linux')]
|
||||
public function testGlibcFlavourIsDetected(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$oldPath = getenv('PATH');
|
||||
putenv('PATH=' . realpath(self::GLIBC_PATH) . PATH_SEPARATOR . $oldPath);
|
||||
|
||||
self::assertSame(LibcFlavour::Gnu, LibcFlavour::detect());
|
||||
|
||||
putenv('PATH=' . $oldPath);
|
||||
}
|
||||
|
||||
#[RequiresOperatingSystemFamily('Linux')]
|
||||
public function testMuslFlavourIsDetected(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$oldPath = getenv('PATH');
|
||||
putenv('PATH=' . realpath(self::MUSL_PATH) . PATH_SEPARATOR . $oldPath);
|
||||
|
||||
self::assertSame(LibcFlavour::Musl, LibcFlavour::detect());
|
||||
|
||||
putenv('PATH=' . $oldPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use Composer\IO\BufferIO;
|
||||
use Composer\Util\Platform;
|
||||
use Php\Pie\ExtensionName;
|
||||
use Php\Pie\Platform\Architecture;
|
||||
use Php\Pie\Platform\DebugBuild;
|
||||
use Php\Pie\Platform\OperatingSystem;
|
||||
use Php\Pie\Platform\OperatingSystemFamily;
|
||||
use Php\Pie\Platform\TargetPhp\Exception\ExtensionIsNotLoaded;
|
||||
@@ -448,11 +449,23 @@ final class PhpBinaryPathTest extends TestCase
|
||||
|
||||
public function testDebugBuildModeReturnsDebugWhenYes(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$phpBinary = $this->createPartialMock(PhpBinaryPath::class, ['phpinfo']);
|
||||
|
||||
$phpBinary->expects(self::once())
|
||||
->method('phpinfo')
|
||||
->willReturn('Debug Build => no');
|
||||
|
||||
self::assertSame(DebugBuild::NoDebug, $phpBinary->debugMode());
|
||||
}
|
||||
|
||||
public function testDebugBuildModeReturnsNoDebugWhenNo(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
$phpBinary = $this->createPartialMock(PhpBinaryPath::class, ['phpinfo']);
|
||||
|
||||
$phpBinary->expects(self::once())
|
||||
->method('phpinfo')
|
||||
->willReturn('Debug Build => yes');
|
||||
|
||||
self::assertSame(DebugBuild::Debug, $phpBinary->debugMode());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +110,9 @@ TEXT);
|
||||
|
||||
public function testLibcFlavourIsMemoized(): void
|
||||
{
|
||||
self::fail('todo'); // @todo 436
|
||||
self::assertSame(
|
||||
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null)->libcFlavour(),
|
||||
TargetPlatform::fromPhpBinaryPath(PhpBinaryPath::fromCurrentProcess(), null)->libcFlavour(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user