-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathAssertRunner.php
More file actions
97 lines (78 loc) · 2.1 KB
/
AssertRunner.php
File metadata and controls
97 lines (78 loc) · 2.1 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
92
93
94
95
96
97
<?php
namespace CzProject\GitPhp\Tests;
use CzProject\GitPhp\CommandProcessor;
use CzProject\GitPhp\GitException;
use CzProject\GitPhp\IRunner;
use CzProject\GitPhp\RunnerResult;
class AssertRunner implements \CzProject\GitPhp\IRunner
{
/** @var string */
private $cwd;
/** @var CommandProcessor */
private $commandProcessor;
/** @var RunnerResult[] */
private $asserts = [];
/**
* @param string $cwd
*/
public function __construct($cwd)
{
$this->cwd = $cwd;
$this->commandProcessor = new CommandProcessor;
}
/**
* Add a configuration parameter to the command.
* @param string $name
* @param mixed $value
*/
public function addConfig($name, $value)
{
$this->commandProcessor->addConfig($name, $value);
}
/**
* @param mixed[] $expectedArgs
* @param array<string, scalar> $expectedEnv
* @param string[] $resultOutput
* @param string[] $resultErrorOutput
* @param int $resultExitCode
* @return self
*/
public function assert(array $expectedArgs, array $expectedEnv = [], array $resultOutput = [], array $resultErrorOutput = [], $resultExitCode = 0)
{
$cmd = $this->commandProcessor->process('git', $expectedArgs, $expectedEnv);
$this->asserts[] = new RunnerResult($cmd, $resultExitCode, $resultOutput, $resultErrorOutput);
return $this;
}
/**
* @return self
*/
public function resetAsserts()
{
$this->asserts = [];
return $this;
}
/**
* @return RunnerResult
*/
public function run($cwd, array $args, array $env = NULL)
{
if (empty($this->asserts)) {
throw new \CzProject\GitPhp\InvalidStateException('Missing asserts, use $runner->assert().');
}
$cmd = $this->commandProcessor->process('git', $args, $env);
$result = current($this->asserts);
if (!($result instanceof RunnerResult)) {
throw new \CzProject\GitPhp\InvalidStateException("Missing assert for command '$cmd'");
}
\Tester\Assert::same($result->getCommand(), $cmd);
next($this->asserts);
return $result;
}
/**
* @return string
*/
public function getCwd()
{
return $this->cwd;
}
}