Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/File/Sudo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Php\Pie\File;

use Composer\Util\Platform as ComposerPlatform;
use Php\Pie\Platform;
use Php\Pie\Platform\TargetPlatform;
use Symfony\Component\Process\ExecutableFinder;
Expand All @@ -23,6 +24,10 @@ final class Sudo
*/
public static function find(): string
{
if (ComposerPlatform::isWindows()) {
throw SudoNotFoundOnSystem::new();
}

if (! is_string(self::$memoizedSudo)) {
$sudo = (new ExecutableFinder())->find('sudo');

Expand Down
27 changes: 27 additions & 0 deletions test/unit/File/SudoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Php\PieUnitTest\File;

use Composer\Util\Platform as ComposerPlatform;
use Php\Pie\File\Sudo;
use Php\Pie\File\SudoNotFoundOnSystem;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(Sudo::class)]
final class SudoTest extends TestCase
{
public function testSudoIsNeverDetectedOnWindows(): void
{
if (! ComposerPlatform::isWindows()) {
self::markTestSkipped('This test only applies to Windows, where a native `sudo.exe` may exist but is not usable by PIE');
}

self::assertFalse(Sudo::exists());

$this->expectException(SudoNotFoundOnSystem::class);
Sudo::find();
}
}