generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Fidry CPUCounter Config package. | ||
* | ||
* (c) Théo FIDRY <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fidry\CpuCoreCounter\Test\Exec; | ||
|
||
use Fidry\CpuCoreCounter\Exec\ExecException; | ||
use Fidry\CpuCoreCounter\Exec\ShellExec; | ||
use PHPUnit\Framework\TestCase; | ||
use const PHP_EOL; | ||
|
||
/** | ||
* @covers \Fidry\CpuCoreCounter\Exec\ExecException | ||
* @covers \Fidry\CpuCoreCounter\Exec\ShellExec | ||
* | ||
* @internal | ||
*/ | ||
final class ShellExecTest extends TestCase | ||
{ | ||
public function test_it_can_execute_a_command_writing_output_to_the_stdout(): void | ||
{ | ||
$command = 'echo "Hello world!"'; | ||
|
||
$expected = 'Hello world!'.PHP_EOL; | ||
$actual = ShellExec::execute($command); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
|
||
public function test_it_can_execute_a_command_writing_output_to_the_stderr_instead_of_the_stdout(): void | ||
{ | ||
self::markTestSkipped('This is messing up with the output.'); | ||
$command = 'echo "Hello world!" 1>&2'; | ||
|
||
$this->expectException(ExecException::class); | ||
$this->expectExceptionMessage('The command "echo "Hello world!" 1>&2" exited without writing to the STDOUT.'); | ||
|
||
ShellExec::execute($command); | ||
} | ||
|
||
public function test_it_can_execute_a_command_writing_output_to_the_stdout_instead_of_the_stderr(): void | ||
{ | ||
$command = 'echoerr() { echo "$@" 1>&2; }; echoerr "Hello world!" 2>&1'; | ||
|
||
$expected = 'Hello world!'.PHP_EOL; | ||
$actual = ShellExec::execute($command); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
} |