Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed May 14, 2024
1 parent c2278a0 commit bd88917
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions tests/unit/Util/PHP/DefaultJobRunnerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Util\PHP;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;

#[CoversClass(DefaultJobRunner::class)]
#[UsesClass(Job::class)]
#[UsesClass(Result::class)]
#[Small]
final class DefaultJobRunnerTest extends TestCase
{
public static function provider(): array
{
return [
'output to stdout' => [
new Result('test', ''),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
fwrite(STDOUT, 'test');
EOT
),
],
'output to stderr: yes' => [
new Result('', 'test'),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
fwrite(STDERR, 'test');
EOT
),
],
'output to stdout and stderr' => [
new Result('test-stdout', 'test-stderr'),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
fwrite(STDOUT, 'test-stdout');
fwrite(STDERR, 'test-stderr');
EOT
),
],
'redirect stderr to stdout' => [
new Result('test', ''),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
fwrite(STDERR, 'test');
EOT,
redirectErrors: true,
),
],
'environment variables' => [
new Result('test', ''),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
print getenv('test');
EOT,
environmentVariables: ['test' => 'test'],
),
],
'arguments' => [
new Result('test', ''),
new Job(
<<<'EOT'
<?php declare(strict_types=1);
print $argv[1];
EOT,
arguments: ['test'],
),
],
];
}

#[DataProvider('provider')]
public function testRunsJobInSeparateProcess(Result $expected, Job $job): void
{
$jobRunner = new DefaultJobRunner;

$result = $jobRunner->run($job);

$this->assertSame($expected->stdout(), $result->stdout());
$this->assertSame($expected->stderr(), $result->stderr());
}
}

0 comments on commit bd88917

Please sign in to comment.