-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathCommandExecutorTest.php
More file actions
91 lines (70 loc) · 2.54 KB
/
Copy pathCommandExecutorTest.php
File metadata and controls
91 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
declare(strict_types=1);
namespace Tests\PHPCensor\Helper;
use Exception;
use PHPCensor\Helper\CommandExecutor;
use PHPCensor\Logging\BuildLogger;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
class CommandExecutorTest extends TestCase
{
use ProphecyTrait;
protected CommandExecutor $testedExecutor;
protected function setUp(): void
{
parent::setUp();
$buildLogger = $this->prophesize(BuildLogger::class);
$class = CommandExecutor::class;
$this->testedExecutor = new $class($buildLogger->reveal(), __DIR__);
}
public function testGetLastOutput_ReturnsOutputOfCommand(): void
{
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
$output = $this->testedExecutor->getLastOutput();
self::assertEquals("Hello World", $output);
}
public function testGetLastOutput_ForgetsPreviousCommandOutput(): void
{
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello Tester']);
$output = $this->testedExecutor->getLastOutput();
self::assertEquals("Hello Tester", $output);
}
public function testExecuteCommand_ReturnsTrueForValidCommands(): void
{
$returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
self::assertTrue($returnValue);
}
public function testExecuteCommand_ReturnsFalseForInvalidCommands(): void
{
$returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']);
self::assertFalse($returnValue);
}
public function testFindBinary_ThrowsWhenNotFound(): void
{
self::expectException(Exception::class);
$thisFileName = "WorldWidePeace";
$this->testedExecutor->findBinary($thisFileName);
}
public function testReplaceIllegalCharacters(): void
{
self::assertEquals(
"start � end",
$this->testedExecutor->replaceIllegalCharacters(
"start \xf0\x9c\x83\x96 end"
)
);
self::assertEquals(
"start � end",
$this->testedExecutor->replaceIllegalCharacters(
"start \xF0\x9C\x83\x96 end"
)
);
self::assertEquals(
"start 123_X08�_X00�_Xa4�_5432 end",
$this->testedExecutor->replaceIllegalCharacters(
"start 123_X08\x08_X00\x00_Xa4\xa4_5432 end"
)
);
}
}