Skip to content

Commit

Permalink
Merge pull request #180 from asgrim/check-additional-php-ini-dir-writ…
Browse files Browse the repository at this point in the history
…able

Check the additional php.ini dir is writable
  • Loading branch information
asgrim authored Jan 29, 2025
2 parents 22f0187 + bf869f4 commit a582bb3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit a582bb3

Please sign in to comment.