Skip to content

Commit a8a40d9

Browse files
authored
[10.x] Test Improvements (#50864)
Use `#[RequiresOperatingSystem('Linux|DAR')]` instead of checking `windows_os()` Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 7bc70f2 commit a8a40d9

File tree

1 file changed

+13
-48
lines changed

1 file changed

+13
-48
lines changed

tests/Process/ProcessTest.php

Lines changed: 13 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Process\Exceptions\ProcessTimedOutException;
88
use Illuminate\Process\Factory;
99
use OutOfBoundsException;
10+
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
1011
use PHPUnit\Framework\TestCase;
1112
use RuntimeException;
1213

@@ -424,12 +425,9 @@ public function testFakeProcessesDontThrowIfFalse()
424425
$this->assertTrue(true);
425426
}
426427

428+
#[RequiresOperatingSystem('Linux|DAR')]
427429
public function testRealProcessesCanHaveErrorOutput()
428430
{
429-
if (windows_os()) {
430-
$this->markTestSkipped('Requires Linux.');
431-
}
432-
433431
$factory = new Factory;
434432
$result = $factory->path(__DIR__)->run('echo "Hello World" >&2; exit 1;');
435433

@@ -455,12 +453,9 @@ public function testFakeProcessesCanThrowWithoutOutput()
455453
$result->throw();
456454
}
457455

456+
#[RequiresOperatingSystem('Linux|DAR')]
458457
public function testRealProcessesCanThrowWithoutOutput()
459458
{
460-
if (windows_os()) {
461-
$this->markTestSkipped('Requires Linux.');
462-
}
463-
464459
$this->expectException(ProcessFailedException::class);
465460
$this->expectExceptionMessage(<<<'EOT'
466461
The command "exit 1;" failed.
@@ -496,12 +491,9 @@ public function testFakeProcessesCanThrowWithErrorOutput()
496491
$result->throw();
497492
}
498493

494+
#[RequiresOperatingSystem('Linux|DAR')]
499495
public function testRealProcessesCanThrowWithErrorOutput()
500496
{
501-
if (windows_os()) {
502-
$this->markTestSkipped('Requires Linux.');
503-
}
504-
505497
$this->expectException(ProcessFailedException::class);
506498
$this->expectExceptionMessage(<<<'EOT'
507499
The command "echo "Hello World" >&2; exit 1;" failed.
@@ -541,12 +533,9 @@ public function testFakeProcessesCanThrowWithOutput()
541533
$result->throw();
542534
}
543535

536+
#[RequiresOperatingSystem('Linux|DAR')]
544537
public function testRealProcessesCanThrowWithOutput()
545538
{
546-
if (windows_os()) {
547-
$this->markTestSkipped('Requires Linux.');
548-
}
549-
550539
$this->expectException(ProcessFailedException::class);
551540
$this->expectExceptionMessage(<<<'EOT'
552541
The command "echo "Hello World" >&1; exit 1;" failed.
@@ -565,12 +554,9 @@ public function testRealProcessesCanThrowWithOutput()
565554
$result->throw();
566555
}
567556

557+
#[RequiresOperatingSystem('Linux|DAR')]
568558
public function testRealProcessesCanTimeout()
569559
{
570-
if (windows_os()) {
571-
$this->markTestSkipped('Requires Linux.');
572-
}
573-
574560
$this->expectException(ProcessTimedOutException::class);
575561
$this->expectExceptionMessage(
576562
'The process "sleep 2; exit 1;" exceeded the timeout of 1 seconds.'
@@ -582,12 +568,9 @@ public function testRealProcessesCanTimeout()
582568
$result->throw();
583569
}
584570

571+
#[RequiresOperatingSystem('Linux|DAR')]
585572
public function testRealProcessesCanThrowIfTrue()
586573
{
587-
if (windows_os()) {
588-
$this->markTestSkipped('Requires Linux.');
589-
}
590-
591574
$this->expectException(ProcessFailedException::class);
592575

593576
$factory = new Factory;
@@ -596,12 +579,9 @@ public function testRealProcessesCanThrowIfTrue()
596579
$result->throwIf(true);
597580
}
598581

582+
#[RequiresOperatingSystem('Linux|DAR')]
599583
public function testRealProcessesDoesntThrowIfFalse()
600584
{
601-
if (windows_os()) {
602-
$this->markTestSkipped('Requires Linux.');
603-
}
604-
605585
$factory = new Factory;
606586
$result = $factory->path(__DIR__)->run('echo "Hello World" >&2; exit 1;');
607587

@@ -610,24 +590,18 @@ public function testRealProcessesDoesntThrowIfFalse()
610590
$this->assertTrue(true);
611591
}
612592

593+
#[RequiresOperatingSystem('Linux|DAR')]
613594
public function testRealProcessesCanUseStandardInput()
614595
{
615-
if (windows_os()) {
616-
$this->markTestSkipped('Requires Linux.');
617-
}
618-
619596
$factory = new Factory();
620597
$result = $factory->input('foobar')->run('cat');
621598

622599
$this->assertSame('foobar', $result->output());
623600
}
624601

602+
#[RequiresOperatingSystem('Linux|DAR')]
625603
public function testProcessPipe()
626604
{
627-
if (windows_os()) {
628-
$this->markTestSkipped('Requires Linux.');
629-
}
630-
631605
$factory = new Factory;
632606
$factory->fake([
633607
'cat *' => "Hello, world\nfoo\nbar",
@@ -641,12 +615,9 @@ public function testProcessPipe()
641615
$this->assertSame("foo\n", $pipe->output());
642616
}
643617

618+
#[RequiresOperatingSystem('Linux|DAR')]
644619
public function testProcessPipeFailed()
645620
{
646-
if (windows_os()) {
647-
$this->markTestSkipped('Requires Linux.');
648-
}
649-
650621
$factory = new Factory;
651622
$factory->fake([
652623
'cat *' => $factory->result(exitCode: 1),
@@ -660,12 +631,9 @@ public function testProcessPipeFailed()
660631
$this->assertTrue($pipe->failed());
661632
}
662633

634+
#[RequiresOperatingSystem('Linux|DAR')]
663635
public function testProcessSimplePipe()
664636
{
665-
if (windows_os()) {
666-
$this->markTestSkipped('Requires Linux.');
667-
}
668-
669637
$factory = new Factory;
670638
$factory->fake([
671639
'cat *' => "Hello, world\nfoo\nbar",
@@ -679,12 +647,9 @@ public function testProcessSimplePipe()
679647
$this->assertSame("foo\n", $pipe->output());
680648
}
681649

650+
#[RequiresOperatingSystem('Linux|DAR')]
682651
public function testProcessSimplePipeFailed()
683652
{
684-
if (windows_os()) {
685-
$this->markTestSkipped('Requires Linux.');
686-
}
687-
688653
$factory = new Factory;
689654
$factory->fake([
690655
'cat *' => $factory->result(exitCode: 1),

0 commit comments

Comments
 (0)