Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v5
- uses: ramsey/composer-install@v3
- name: GH token
- name: GH token (non-Windows)
if: matrix.operating-system != 'windows-latest'
run: sudo composer config --global --auth github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
- name: GH token (Windows)
if: matrix.operating-system == 'windows-latest'
run: composer config --global --auth github-oauth.github.com ${{ secrets.GITHUB_TOKEN }}
- name: Run PHPUnit on Windows
if: matrix.operating-system == 'windows-latest'
run: vendor/bin/phpunit
Expand Down
46 changes: 45 additions & 1 deletion src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use function is_executable;
use function mkdir;
use function preg_match;
use function preg_replace;
use function sprintf;
use function strtolower;
use function trim;
Expand Down Expand Up @@ -370,7 +371,50 @@ public static function fromCurrentProcess(): self

self::assertValidLookingPhpBinary($phpExecutable);

return new self($phpExecutable, null);
return self::guessWithPhpConfig(new self($phpExecutable, null));
}

private static function guessWithPhpConfig(self $phpBinaryPath): self
{
$phpConfigAttempts = [];

// Try to add `phpize` from path
$whichPhpize = new \Symfony\Component\Process\Process(['which', 'php-config']);
if ($whichPhpize->run() === 0) {
$phpConfigAttempts[] = trim($whichPhpize->getOutput());
}

$phpConfigAttempts[] = preg_replace('((.*)php)', '$1php-config', $phpBinaryPath->phpBinaryPath);

foreach ($phpConfigAttempts as $phpConfigAttempt) {
assert($phpConfigAttempt !== null);
assert($phpConfigAttempt !== '');
if (! file_exists($phpConfigAttempt) || ! is_executable($phpConfigAttempt)) {
continue;
}

$phpizeProcess = new \Symfony\Component\Process\Process([$phpConfigAttempt, '--php-binary']);
if ($phpizeProcess->run() !== 0) {
continue;
}

if (trim($phpizeProcess->getOutput()) !== $phpBinaryPath->phpBinaryPath) {
continue;
}

$phpConfigApiVersionProcess = new \Symfony\Component\Process\Process([$phpConfigAttempt, '--phpapi']);

// older versions of php-config did not have `--phpapi`, so we can't perform this validation
if ($phpConfigApiVersionProcess->run() !== 0) {
return new self($phpBinaryPath->phpBinaryPath, $phpConfigAttempt);
}

if (trim($phpConfigApiVersionProcess->getOutput()) === $phpBinaryPath->phpApiVersion()) {
return new self($phpBinaryPath->phpBinaryPath, $phpConfigAttempt);
}
}

return $phpBinaryPath;
}

private static function cleanWarningAndDeprecationsFromOutput(string $testOutput): string
Expand Down
2 changes: 1 addition & 1 deletion test/behaviour/CliContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function theExtensionShouldHaveBeenBuilt(): void
}

Assert::contains($this->output, 'phpize complete.');
Assert::contains($this->output, 'Configure complete.');
Assert::contains($this->output, 'Configure complete');
Assert::contains($this->output, 'Build complete:');
}

Expand Down
2 changes: 1 addition & 1 deletion test/integration/Command/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testBuildCommandWillBuildTheExtension(): void
}

self::assertStringContainsString('phpize complete.', $outputString);
self::assertStringContainsString('Configure complete.', $outputString);
self::assertStringContainsString('Configure complete', $outputString);
self::assertStringContainsString('Build complete:', $outputString);
}
}
21 changes: 5 additions & 16 deletions test/integration/Downloading/GithubPackageReleaseAssetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Php\PieIntegrationTest\Downloading;

use Composer\Config;
use Composer\IO\IOInterface;
use Composer\Factory;
use Composer\IO\NullIO;
use Composer\Package\CompletePackage;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
Expand All @@ -25,9 +25,6 @@
use PHPUnit\Framework\Attributes\RequiresOperatingSystemFamily;
use PHPUnit\Framework\TestCase;

use function getenv;
use function is_string;

#[CoversClass(GithubPackageReleaseAssets::class)]
final class GithubPackageReleaseAssetsTest extends TestCase
{
Expand Down Expand Up @@ -58,17 +55,9 @@ public function testDeterminingReleaseAssetUrlForWindows(): void
'https://api.github.com/repos/asgrim/example-pie-extension/zipball/f9ed13ea95dada34c6cc5a052da258dbda059d27',
);

$io = $this->createMock(IOInterface::class);

$githubToken = getenv('GITHUB_TOKEN');
if (is_string($githubToken) && $githubToken !== '') {
$io->method('hasAuthentication')
->willReturn(true);
$io->method('getAuthentication')
->willReturn(['username' => $githubToken, 'password' => 'x-oauth-basic']);
}

$config = new Config();
$io = new NullIO();
$config = Factory::createConfig();
$io->loadConfiguration($config);

self::assertSame(
'https://github.com/asgrim/example-pie-extension/releases/download/2.0.2/php_example_pie_extension-2.0.2-8.3-ts-vs16-x86_64.zip',
Expand Down
9 changes: 8 additions & 1 deletion test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Php\Pie\Platform\TargetPhp\Exception\ExtensionIsNotLoaded;
use Php\Pie\Platform\TargetPhp\Exception\InvalidPhpBinaryPath;
use Php\Pie\Platform\TargetPhp\PhpBinaryPath;
use Php\Pie\Util\Process;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -104,7 +105,13 @@ public function testVersionFromCurrentProcess(): void
PHP_VERSION,
$phpBinary->version(),
);
self::assertNull($phpBinary->phpConfigPath());

$phpConfig = $phpBinary->phpConfigPath();
if ($phpConfig === null) {
return;
}

self::assertSame($phpBinary->phpBinaryPath, Process::run([$phpConfig, '--php-binary']));
}

/** @return array<string, array{0: non-empty-string, 1: non-empty-string}> */
Expand Down
Loading