1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Overwatch\TestBundle\Tests\Command; |
4
|
|
|
|
5
|
|
|
use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* ConsoleTestHelperTrait |
9
|
|
|
*/ |
10
|
|
|
trait ConsoleTestHelperTrait |
11
|
|
|
{ |
12
|
|
|
protected $output = null; |
13
|
|
|
|
14
|
|
|
public function assertHasStandardOutput() |
15
|
|
|
{ |
16
|
|
|
$this->assertStringStartsWith($this->application->getName(), $this->output[0]); |
|
|
|
|
17
|
|
|
$this->assertContains($this->application->getVersion(), $this->output[0]); |
|
|
|
|
18
|
|
|
|
19
|
|
|
foreach ($this->output as $lineNum => $line) { |
20
|
|
|
if ($lineNum === 0 || $lineNum === count($this->output) - 1) { |
21
|
|
|
continue; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
$this->assertStringStartsWith(' > ', $line); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param integer $count |
30
|
|
|
*/ |
31
|
|
|
public function assertCountLinesOfOutput($count) |
32
|
|
|
{ |
33
|
|
|
$this->assertCount($count, $this->output); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param integer $count |
38
|
|
|
*/ |
39
|
|
|
public function assertCountRunTests($count = null) |
40
|
|
|
{ |
41
|
|
|
if ($count === null) { |
42
|
|
|
$count = count(TestFixtures::$tests); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$this->assertStringEndsWith("$count tests", $this->output[0]); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function assertResults($failed = '[0-9]+', $error = '[0-9]+', $unsatisfactory = '[0-9]+', $passed = '[0-9]+') |
49
|
|
|
{ |
50
|
|
|
$this->assertRegExp( |
|
|
|
|
51
|
|
|
"/^$failed FAILED, $error ERROR, $unsatisfactory UNSATISFACTORY, $passed PASSED/", |
|
|
|
|
52
|
|
|
$this->output[count($this->output) - 1] |
53
|
|
|
); |
54
|
|
|
$this->assertRegExp('/, in [0-9]+ minutes and [0-9]+ seconds$/i', $this->output[count($this->output) - 1]); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function assertRecentResultsPersisted($count = 3) |
58
|
|
|
{ |
59
|
|
|
$now = (new \DateTime())->getTimestamp(); |
60
|
|
|
$results = $this->resultRepo->getResults([], $count); |
|
|
|
|
61
|
|
|
|
62
|
|
|
foreach ($results as $result) { |
63
|
|
|
$diff = $now - $result->getCreatedAt()->getTimestamp(); |
64
|
|
|
|
65
|
|
|
$this->assertLessThan(60, $diff); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function assertRecentResultsNotPersisted() |
70
|
|
|
{ |
71
|
|
|
$result = $this->resultRepo->getResults([], 1); |
72
|
|
|
|
73
|
|
|
$this->assertGreaterThan(500, $result[0]->getCreatedAt()->getTimestamp()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function execute($params = [], $options = []) |
77
|
|
|
{ |
78
|
|
|
$params['command'] = self::COMMAND_NAME; |
79
|
|
|
$returnCode = $this->command->execute($params, $options); |
|
|
|
|
80
|
|
|
|
81
|
|
|
$this->output = explode(PHP_EOL, $this->command->getDisplay()); |
82
|
|
|
$lastLine = array_pop($this->output); |
83
|
|
|
|
84
|
|
|
if (!empty($lastLine)) { |
85
|
|
|
array_push($this->output, $lastLine); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $returnCode; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: