Skip to content

Commit

Permalink
[10.x] Test Improvements (#50864)
Browse files Browse the repository at this point in the history
Use `#[RequiresOperatingSystem('Linux|DAR')]` instead of checking
`windows_os()`

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Apr 1, 2024
1 parent 7bc70f2 commit a8a40d9
Showing 1 changed file with 13 additions and 48 deletions.
61 changes: 13 additions & 48 deletions tests/Process/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Process\Exceptions\ProcessTimedOutException;
use Illuminate\Process\Factory;
use OutOfBoundsException;
use PHPUnit\Framework\Attributes\RequiresOperatingSystem;
use PHPUnit\Framework\TestCase;
use RuntimeException;

Expand Down Expand Up @@ -424,12 +425,9 @@ public function testFakeProcessesDontThrowIfFalse()
$this->assertTrue(true);
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanHaveErrorOutput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$result = $factory->path(__DIR__)->run('echo "Hello World" >&2; exit 1;');

Expand All @@ -455,12 +453,9 @@ public function testFakeProcessesCanThrowWithoutOutput()
$result->throw();
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanThrowWithoutOutput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$this->expectException(ProcessFailedException::class);
$this->expectExceptionMessage(<<<'EOT'
The command "exit 1;" failed.
Expand Down Expand Up @@ -496,12 +491,9 @@ public function testFakeProcessesCanThrowWithErrorOutput()
$result->throw();
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanThrowWithErrorOutput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$this->expectException(ProcessFailedException::class);
$this->expectExceptionMessage(<<<'EOT'
The command "echo "Hello World" >&2; exit 1;" failed.
Expand Down Expand Up @@ -541,12 +533,9 @@ public function testFakeProcessesCanThrowWithOutput()
$result->throw();
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanThrowWithOutput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$this->expectException(ProcessFailedException::class);
$this->expectExceptionMessage(<<<'EOT'
The command "echo "Hello World" >&1; exit 1;" failed.
Expand All @@ -565,12 +554,9 @@ public function testRealProcessesCanThrowWithOutput()
$result->throw();
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanTimeout()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$this->expectException(ProcessTimedOutException::class);
$this->expectExceptionMessage(
'The process "sleep 2; exit 1;" exceeded the timeout of 1 seconds.'
Expand All @@ -582,12 +568,9 @@ public function testRealProcessesCanTimeout()
$result->throw();
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanThrowIfTrue()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$this->expectException(ProcessFailedException::class);

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

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesDoesntThrowIfFalse()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$result = $factory->path(__DIR__)->run('echo "Hello World" >&2; exit 1;');

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

#[RequiresOperatingSystem('Linux|DAR')]
public function testRealProcessesCanUseStandardInput()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory();
$result = $factory->input('foobar')->run('cat');

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

#[RequiresOperatingSystem('Linux|DAR')]
public function testProcessPipe()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$factory->fake([
'cat *' => "Hello, world\nfoo\nbar",
Expand All @@ -641,12 +615,9 @@ public function testProcessPipe()
$this->assertSame("foo\n", $pipe->output());
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testProcessPipeFailed()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$factory->fake([
'cat *' => $factory->result(exitCode: 1),
Expand All @@ -660,12 +631,9 @@ public function testProcessPipeFailed()
$this->assertTrue($pipe->failed());
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testProcessSimplePipe()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$factory->fake([
'cat *' => "Hello, world\nfoo\nbar",
Expand All @@ -679,12 +647,9 @@ public function testProcessSimplePipe()
$this->assertSame("foo\n", $pipe->output());
}

#[RequiresOperatingSystem('Linux|DAR')]
public function testProcessSimplePipeFailed()
{
if (windows_os()) {
$this->markTestSkipped('Requires Linux.');
}

$factory = new Factory;
$factory->fake([
'cat *' => $factory->result(exitCode: 1),
Expand Down

0 comments on commit a8a40d9

Please sign in to comment.