1
|
|
|
<?php |
2
|
|
|
namespace Robo\Traits; |
3
|
|
|
|
4
|
|
|
use Robo\Robo; |
5
|
|
|
use Robo\TaskAccessor; |
6
|
|
|
use Robo\Collection\CollectionBuilder; |
7
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
8
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
9
|
|
|
|
10
|
|
|
trait TestTasksTrait |
11
|
|
|
{ |
12
|
|
|
use TaskAccessor; |
13
|
|
|
|
14
|
|
|
protected $testPrinter; |
15
|
|
|
protected $capturedOutput; |
16
|
|
|
protected $logger; |
17
|
|
|
|
18
|
|
|
public function initTestTasksTrait($commandClass = null, $container = null, $input = null) |
19
|
|
|
{ |
20
|
|
|
if (!$container) { |
21
|
|
|
$container = Robo::createDefaultContainer(); |
22
|
|
|
} |
23
|
|
|
$this->capturedOutput = ''; |
24
|
|
|
$this->testPrinter = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG); |
25
|
|
|
|
26
|
|
|
$app = Robo::createDefaultApplication(); |
27
|
|
|
$config = new \Robo\Config(); |
|
|
|
|
28
|
|
|
\Robo\Robo::configureContainer($container, $app, $config, $input, $this->testPrinter); |
29
|
|
|
|
30
|
|
|
// Set the application dispatcher |
31
|
|
|
$app->setDispatcher($container->get('eventDispatcher')); |
32
|
|
|
$this->logger = $container->get('logger'); |
33
|
|
|
|
34
|
|
|
// Use test class as command class if a specific one is not provided |
35
|
|
|
if (!$commandClass) { |
36
|
|
|
$commandClass = $this; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if ($commandClass instanceof Psr\Log\LoggerAwareInterface) { |
40
|
|
|
$commandClass->setLogger($this->logger); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// Configure BuilderAwareTrait |
44
|
|
|
$builder = CollectionBuilder::create($container, $commandClass); |
45
|
|
|
$commandClass->setBuilder($builder); |
46
|
|
|
$this->setBuilder($builder); |
47
|
|
|
|
48
|
|
|
return $container; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function capturedOutputStream() |
52
|
|
|
{ |
53
|
|
|
if (!$this->testPrinter) { |
54
|
|
|
$this->initTestTasksTrait(); |
55
|
|
|
} |
56
|
|
|
return $this->testPrinter; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function logger() |
60
|
|
|
{ |
61
|
|
|
return $this->logger; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
protected function accumulate() |
65
|
|
|
{ |
66
|
|
|
$this->capturedOutput .= $this->capturedOutputStream()->fetch(); |
67
|
|
|
return $this->capturedOutput; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function assertOutputContains($value) |
71
|
|
|
{ |
72
|
|
|
$output = $this->accumulate(); |
73
|
|
|
$output = $this->simplify($output); |
74
|
|
|
$this->assertContains($value, $output); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function assertOutputNotContains($value) |
78
|
|
|
{ |
79
|
|
|
$output = $this->accumulate(); |
80
|
|
|
$output = $this->simplify($output); |
81
|
|
|
$this->assertNotContains($value, $output); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function assertOutputEquals($value) |
85
|
|
|
{ |
86
|
|
|
$output = $this->accumulate(); |
87
|
|
|
$output = $this->simplify($output); |
88
|
|
|
$this->assertEquals($value, $output); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Make our output comparisons more platform-agnostic by converting |
93
|
|
|
* CRLF (Windows) or raw CR (confused output) to a LF (unix/Mac). |
94
|
|
|
*/ |
95
|
|
View Code Duplication |
protected function simplify($output) |
|
|
|
|
96
|
|
|
{ |
97
|
|
|
$output = str_replace("\r\n", "\n", $output); |
98
|
|
|
$output = str_replace("\r", "\n", $output); |
99
|
|
|
|
100
|
|
|
return $output; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.