-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathCommandExecutorTest.php
More file actions
87 lines (71 loc) · 2.5 KB
/
Copy pathCommandExecutorTest.php
File metadata and controls
87 lines (71 loc) · 2.5 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
<?php
namespace Tests\PHPCensor\Helper;
use Exception;
use PHPCensor\Helper\CommandExecutor;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
class CommandExecutorTest extends TestCase
{
use ProphecyTrait;
/**
* @var CommandExecutor
*/
protected $testedExecutor;
protected function setUp(): void
{
parent::setUp();
$mockBuildLogger = $this->prophesize('PHPCensor\Logging\BuildLogger');
$class = 'PHPCensor\Helper\CommandExecutor';
$this->testedExecutor = new $class($mockBuildLogger->reveal(), __DIR__);
}
public function testGetLastOutput_ReturnsOutputOfCommand()
{
$this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
$output = $this->testedExecutor->getLastOutput();
self::assertEquals("Hello World", $output);
}
public function testGetLastOutput_ForgetsPreviousCommandOutput()
{
$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()
{
$returnValue = $this->testedExecutor->executeCommand(['echo "%s"', 'Hello World']);
self::assertTrue($returnValue);
}
public function testExecuteCommand_ReturnsFalseForInvalidCommands()
{
$returnValue = $this->testedExecutor->executeCommand(['eerfdcvcho "%s" > /dev/null 2>&1', 'Hello World']);
self::assertFalse($returnValue);
}
public function testFindBinary_ThrowsWhenNotFound()
{
self::expectException(Exception::class);
$thisFileName = "WorldWidePeace";
$this->testedExecutor->findBinary($thisFileName);
}
public function testReplaceIllegalCharacters()
{
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"
)
);
}
}