Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the additional php.ini dir is writable #180

Merged
merged 1 commit into from
Jan 29, 2025
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
13 changes: 13 additions & 0 deletions src/Installing/Ini/StandardAdditionalPhpIniDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Console\Output\OutputInterface;

use function file_exists;
use function is_writable;
use function rtrim;
use function sprintf;
use function touch;
Expand Down Expand Up @@ -43,6 +44,18 @@ public function setup(
return false;
}

if (! file_exists($additionalIniFilesPath) || ! is_writable($additionalIniFilesPath)) {
$output->writeln(
sprintf(
'PHP is configured to use additional INI file path %s, but it did not exist, or is not writable by PIE.',
$additionalIniFilesPath,
),
OutputInterface::VERBOSITY_VERBOSE,
);

return false;
}

$expectedIniFile = sprintf(
'%s%s%d-%s.ini',
rtrim($additionalIniFilesPath, DIRECTORY_SEPARATOR),
Expand Down
23 changes: 23 additions & 0 deletions test/unit/Installing/Ini/StandardAdditionalPhpIniDirectoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ public function testSetupReturnsWhenAdditionalPhpIniDirectoryIsNotSet(): void
));
}

public function testSetupReturnsWhenAdditionalPhpIniDirectoryDoesNotExist(): void
{
$this->mockPhpBinary
->expects(self::once())
->method('additionalIniDirectory')
->willReturn('/path/to/something/does/not/exist');

$this->checkAndAddExtensionToIniIfNeeded
->expects(self::never())
->method('__invoke');

self::assertFalse($this->standardAdditionalPhpIniDirectory->setup(
$this->targetPlatform,
$this->downloadedPackage,
$this->binaryFile,
$this->output,
));
self::assertStringContainsString(
'PHP is configured to use additional INI file path /path/to/something/does/not/exist, but it did not exist, or is not writable by PIE.',
$this->output->fetch(),
);
}

public function testReturnsTrueWhenCheckAndAddExtensionIsInvoked(): void
{
$additionalPhpIniDirectory = tempnam(sys_get_temp_dir(), 'pie_additional_php_ini_path');
Expand Down