File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55namespace Php \Pie \File ;
66
7+ use Composer \Util \Platform as ComposerPlatform ;
78use Php \Pie \Platform ;
89use Php \Pie \Platform \TargetPlatform ;
910use 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments