Skip to content

Commit e71596a

Browse files
authored
Merge pull request #5 from jolicode/windows-10
Add a new helper to detect Windows >= 10
2 parents af3ced6 + d3ccdf6 commit e71596a

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

.github/workflows/ci.yml

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ name: Continuous Integration
66
pull_request: ~
77

88
jobs:
9-
ci:
10-
name: Run the test suite
9+
ci_linux:
10+
name: Run the test suite on Linux
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
@@ -17,7 +17,7 @@ jobs:
1717
- '8.4'
1818

1919
steps:
20-
- uses: actions/checkout@v3
20+
- uses: actions/checkout@v4
2121

2222
- name: Setup PHP
2323
uses: shivammathur/setup-php@v2
@@ -33,12 +33,52 @@ jobs:
3333
- name: Run tests
3434
run: composer test
3535

36+
ci_macos:
37+
name: Run the test suite on macOS
38+
runs-on: macos-latest
39+
steps:
40+
- uses: actions/checkout@v4
41+
42+
- name: Setup PHP
43+
uses: shivammathur/setup-php@v2
44+
with:
45+
php-version: '8.4'
46+
47+
- name: Validate composer.json and composer.lock
48+
run: composer validate --strict
49+
50+
- name: Install dependencies
51+
run: composer install --prefer-dist --no-progress
52+
53+
- name: Run tests
54+
run: composer test
55+
56+
ci_windows:
57+
name: Run the test suite on Windows
58+
runs-on: windows-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
62+
- name: Setup PHP
63+
uses: shivammathur/setup-php@v2
64+
with:
65+
php-version: '8.4'
66+
67+
- name: Validate composer.json and composer.lock
68+
run: composer validate --strict
69+
70+
- name: Install dependencies
71+
run: composer install --prefer-dist --no-progress
72+
73+
- name: Run tests
74+
run: composer test
75+
3676
php-cs-fixer:
3777
name: Run PHP CS Fixer
3878
runs-on: ubuntu-latest
3979

4080
steps:
41-
- uses: actions/checkout@v3
81+
- uses: actions/checkout@v4
4282

4383
- name: Setup PHP
4484
uses: shivammathur/setup-php@v2
@@ -56,7 +96,7 @@ jobs:
5696
runs-on: ubuntu-latest
5797

5898
steps:
59-
- uses: actions/checkout@v3
99+
- uses: actions/checkout@v4
60100

61101
- name: Setup PHP
62102
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
* Drop support of PHP 8.1
66
* Add support of PHP 8.4
7+
* Add new helper `OsHelper::isWindowsTenOrHigher()`
78

89
## 0.2.0 (2024-10-02)
910

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ OsHelper::isUnix(); // true or false
1919
OsHelper::isWindows(); // true or false
2020
OsHelper::isWindowsSeven(); // true or false
2121
OsHelper::isWindowsEightOrHigher(); // true or false
22+
OsHelper::isWindowsTenOrHigher(); // true or false
2223
OsHelper::isWindowsSubsystemForLinux(); // true or false
2324
OsHelper::isMacOs(); // true or false
2425
OsHelper::isDocker(); // true or false

src/OsHelper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ public static function isWindowsEightOrHigher(): bool
4141
return version_compare(self::$kernelVersion, '6.2', '>=');
4242
}
4343

44+
public static function isWindowsTenOrHigher(): bool
45+
{
46+
if (!isset(self::$kernelVersion)) {
47+
self::$kernelVersion = php_uname('r');
48+
}
49+
50+
return version_compare(self::$kernelVersion, '6.4', '>=');
51+
}
52+
4453
public static function isMacOS(): bool
4554
{
4655
if (!isset(self::$kernelName)) {

tests/OsHelperTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,28 @@ public function testIsWindowsEightOrHigher()
5050
'6.2', // 8
5151
'6.3', // 8.1
5252
'6.4', // 10
53-
'10', // 10 or 11, yeah microsoft is doing weird things
53+
'10.0', // 10 or 11, yeah microsoft is doing weird things
5454
];
5555
$isEightOrHigher = \in_array(php_uname('r'), $eightOrHigher, true);
5656

5757
$this->assertSame($isEightOrHigher, OsHelper::isWindowsEightOrHigher());
5858
}
5959

60+
public function testIsWindowsTenOrHigher()
61+
{
62+
if (!OsHelper::isWindows()) {
63+
$this->markTestSkipped('Can only be run on Windows');
64+
}
65+
66+
$tenOrHigher = [
67+
'6.4', // 10
68+
'10.0', // 10 or 11, yeah microsoft is doing weird things
69+
];
70+
$isTenOrHigher = \in_array(php_uname('r'), $tenOrHigher, true);
71+
72+
$this->assertSame($isTenOrHigher, OsHelper::isWindowsTenOrHigher());
73+
}
74+
6075
public function testIsMacOS()
6176
{
6277
$uname = php_uname();
@@ -82,7 +97,7 @@ public function testGetMacOSVersion()
8297

8398
$macOsVersion = OsHelper::getMacOSVersion();
8499

85-
$this->assertRegExp('#\d{1,2}\.\d{1,2}(\.\d{1,2})?#', $macOsVersion);
100+
$this->assertMatchesRegularExpression('#\d{1,2}\.\d{1,2}(\.\d{1,2})?#', $macOsVersion);
86101
$this->assertSame($expectedMacOsVersion, $macOsVersion);
87102
}
88103
}

0 commit comments

Comments
 (0)