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 9, 2024
1 parent b1fd95a commit 8110e8c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 61 deletions.
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testCreateNotInCompatibleOperatingSystemFamiliesException(): voi
);

self::assertSame(
'This extension does not support the "Darwin" operating system family. It is compatible with the following families: "Windows", "Linux".',
'This extension does not support the "darwin" operating system family. It is compatible with the following families: "windows", "linux".',
$exception->getMessage(),
);
}
Expand All @@ -33,7 +33,7 @@ public function testCreateInIncompatibleOperatingSystemFamilyException(): void
);

self::assertSame(
'This extension does not support the "Darwin" operating system family. It is incompatible with the following families: "Windows", "Linux".',
'This extension does not support the "darwin" operating system family. It is incompatible with the following families: "windows", "linux".',
$exception->getMessage(),
);
}
Expand Down
34 changes: 2 additions & 32 deletions test/unit/DependencyResolver/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,6 @@ public function testFromComposerCompletePackageWithOsFamilies(): void
self::assertNull($package->downloadUrl);
}

public function testFromComposerCompletePackageWithEmptyExcludedOsFamilies(): void
{
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
$composerCompletePackage->setPhpExt(['os-families-exclude' => null]);

$package = Package::fromComposerCompletePackage($composerCompletePackage);

self::assertEmpty($package->compatibleOsFamilies);
self::assertEmpty($package->incompatibleOsFamilies);
self::assertSame('vendor/foo', $package->name);
self::assertSame('1.2.3', $package->version);
self::assertSame('vendor/foo:1.2.3', $package->prettyNameAndVersion());
self::assertNull($package->downloadUrl);
}

public function testFromComposerCompletePackageWithEmptyOsFamilies(): void
{
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
$composerCompletePackage->setPhpExt(['os-families' => null]);

$package = Package::fromComposerCompletePackage($composerCompletePackage);

self::assertEmpty($package->compatibleOsFamilies);
self::assertEmpty($package->incompatibleOsFamilies);
self::assertSame('vendor/foo', $package->name);
self::assertSame('1.2.3', $package->version);
self::assertSame('vendor/foo:1.2.3', $package->prettyNameAndVersion());
self::assertNull($package->downloadUrl);
}

public function testFromComposerCompletePackageWithBothOsFamiliesAndExcludedOsFamiliesThrows(): void
{
$composerCompletePackage = new CompletePackage('vendor/foo', '1.2.3.0', '1.2.3');
Expand All @@ -121,7 +91,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 +102,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
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsCompatible(): void
);

$this->expectException(IncompatibleOperatingSystemFamily::class);
$this->expectExceptionMessage('This extension does not support the "Linux" operating system family. It is compatible with the following families: "Solaris", "Darwin"');
$this->expectExceptionMessage('This extension does not support the "linux" operating system family. It is compatible with the following families: "solaris", "darwin"');
(new ResolveDependencyWithComposer(
$this->createMock(QuieterConsoleIO::class),
))(
Expand Down Expand Up @@ -292,7 +292,7 @@ public function testExtensionCanOnlyBeInstalledIfOsFamilyIsNotInCompatible(): vo
);

$this->expectException(IncompatibleOperatingSystemFamily::class);
$this->expectExceptionMessage('This extension does not support the "Darwin" operating system family. It is incompatible with the following families: "Darwin", "Solaris".');
$this->expectExceptionMessage('This extension does not support the "darwin" operating system family. It is incompatible with the following families: "darwin", "solaris".');
(new ResolveDependencyWithComposer(
$this->createMock(QuieterConsoleIO::class),
))(
Expand Down
12 changes: 6 additions & 6 deletions test/unit/Platform/OperatingSystemFamilyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public function testAsValuesList(): void
{
self::assertSame(
[
'Windows',
'BSD',
'Darwin',
'Solaris',
'Linux',
'Unknown',
'windows',
'bsd',
'darwin',
'solaris',
'linux',
'unknown',
],
OperatingSystemFamily::asValuesList(),
);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/Platform/TargetPhp/PhpBinaryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use function php_uname;
use function phpversion;
use function sprintf;
use function strtolower;

use const DIRECTORY_SEPARATOR;
use const PHP_INT_SIZE;
Expand Down Expand Up @@ -169,7 +170,7 @@ public function testOperatingSystem(): void
public function testOperatingSystemFamily(): void
{
self::assertSame(
OperatingSystemFamily::from(PHP_OS_FAMILY),
OperatingSystemFamily::from(strtolower(PHP_OS_FAMILY)),
PhpBinaryPath::fromCurrentProcess()
->operatingSystemFamily(),
);
Expand Down

0 comments on commit 8110e8c

Please sign in to comment.