Skip to content

Commit

Permalink
Lowercase OS family names
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-daubois committed Dec 3, 2024
1 parent b1fd95a commit 03d24dc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions src/DependencyResolver/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use function str_contains;
use function str_starts_with;
use function strtolower;
use function ucfirst;

/**
* @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks
Expand Down Expand Up @@ -134,8 +133,7 @@ private static function convertInputStringsToOperatingSystemFamilies(array|null

$osFamilies = [];
foreach ($input as $value) {
// try to normalize a bit the input
$valueToTry = ucfirst(strtolower($value));
$valueToTry = strtolower($value);

Assert::inArray($valueToTry, OperatingSystemFamily::asValuesList(), 'Expected operating system family to be one of: %2$s. Got: %s');

Expand Down
12 changes: 6 additions & 6 deletions src/Platform/OperatingSystemFamily.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
enum OperatingSystemFamily: string
{
case Windows = 'Windows';
case Bsd = 'BSD';
case Darwin = 'Darwin';
case Solaris = 'Solaris';
case Linux = 'Linux';
case Unknown = 'Unknown';
case Windows = 'windows';
case Bsd = 'bsd';
case Darwin = 'darwin';
case Solaris = 'solaris';
case Linux = 'linux';
case Unknown = 'unknown';

/** @return non-empty-list<non-empty-string> */
public static function asValuesList(): array
Expand Down
3 changes: 2 additions & 1 deletion src/Platform/TargetPhp/PhpBinaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function is_executable;
use function preg_match;
use function sprintf;
use function strtolower;
use function trim;

use const DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -173,7 +174,7 @@ public function operatingSystemFamily(): OperatingSystemFamily
'echo PHP_OS_FAMILY;',
]);

$osFamily = OperatingSystemFamily::tryFrom(trim($output));
$osFamily = OperatingSystemFamily::tryFrom(strtolower(trim($output)));
Assert::notNull($osFamily, 'Could not determine operating system family');

return $osFamily;
Expand Down
4 changes: 2 additions & 2 deletions test/unit/DependencyResolver/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testFromComposerCompletePackageWithTypeInOsFamiliesThrows(): voi
$composerCompletePackage->setPhpExt(['os-families' => ['Not an OS']]);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected operating system family to be one of "Windows", "BSD", "Darwin", "Solaris", "Linux", "Unknown", got "Not an OS".');
$this->expectExceptionMessage('Expected operating system family to be one of: "windows", "bsd", "darwin", "solaris", "linux", "unknown". Got: "not an os"');

Package::fromComposerCompletePackage($composerCompletePackage);
}
Expand All @@ -132,7 +132,7 @@ public function testFromComposerCompletePackageWithTypeInExcludedOsFamiliesThrow
$composerCompletePackage->setPhpExt(['os-families-exclude' => ['Not an OS']]);

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Expected operating system family to be one of "Windows", "BSD", "Darwin", "Solaris", "Linux", "Unknown", got "Not an OS".');
$this->expectExceptionMessage('Expected operating system family to be one of: "windows", "bsd", "darwin", "solaris", "linux", "unknown". Got: "not an os"');

Package::fromComposerCompletePackage($composerCompletePackage);
}
Expand Down

0 comments on commit 03d24dc

Please sign in to comment.