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
<?php
namespace Codeception\Lib\Console;
use SebastianBergmann\Comparator\ComparisonFailure;
use Symfony\Component\Console\Output\OutputInterface;
/**
* MessageFactory
**/
class MessageFactory
{
/**
* @var DiffFactory
*/
protected $diffFactory;
/**
* @var Output
*/
private $output;
/**
* @var Colorizer
*/
protected $colorizer;
/**
* MessageFactory constructor.
* @param Output $output
*/
public function __construct(Output $output)
{
$this->output = $output;
$this->diffFactory = new DiffFactory();
$this->colorizer = new Colorizer();
}
/**
* @param string $text
* @return Message
*/
public function message($text = '')
{
return new Message($text, $this->output);
}
/**
* @param ComparisonFailure $failure
* @return string
*/
public function prepareComparisonFailureMessage(ComparisonFailure $failure)
{
$diff = $this->diffFactory->createDiff($failure);
if (!$diff) {
return '';
}
$diff = $this->colorizer->colorize($diff);
return "\n<comment>- Expected</comment> | <info>+ Actual</info>\n$diff";
}
}