Skip to content

Commit 2fe374e

Browse files
committed
554: do not attempt to use sudo on Windows
1 parent 2d48ace commit 2fe374e

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/File/Sudo.php

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

55
namespace Php\Pie\File;
66

7+
use Composer\Util\Platform as ComposerPlatform;
78
use Php\Pie\Platform;
89
use Php\Pie\Platform\TargetPlatform;
910
use Symfony\Component\Process\ExecutableFinder;
@@ -23,6 +24,10 @@ final class Sudo
2324
*/
2425
public static function find(): string
2526
{
27+
if (ComposerPlatform::isWindows()) {
28+
throw SudoNotFoundOnSystem::new();
29+
}
30+
2631
if (! is_string(self::$memoizedSudo)) {
2732
$sudo = (new ExecutableFinder())->find('sudo');
2833

test/unit/File/SudoTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Php\PieUnitTest\File;
6+
7+
use Composer\Util\Platform as ComposerPlatform;
8+
use Php\Pie\File\Sudo;
9+
use Php\Pie\File\SudoNotFoundOnSystem;
10+
use PHPUnit\Framework\Attributes\CoversClass;
11+
use PHPUnit\Framework\TestCase;
12+
13+
#[CoversClass(Sudo::class)]
14+
final class SudoTest extends TestCase
15+
{
16+
public function testSudoIsNeverDetectedOnWindows(): void
17+
{
18+
if (! ComposerPlatform::isWindows()) {
19+
self::markTestSkipped('This test only applies to Windows, where a native `sudo.exe` may exist but is not usable by PIE');
20+
}
21+
22+
self::assertFalse(Sudo::exists());
23+
24+
$this->expectException(SudoNotFoundOnSystem::class);
25+
Sudo::find();
26+
}
27+
}

0 commit comments

Comments
 (0)