|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yoghi\Bundle\MaddaBundleTest\Utils; |
|
4
|
|
|
|
|
5
|
|
|
use Monolog\Formatter\LineFormatter; |
|
6
|
|
|
use Monolog\Handler\StreamHandler; |
|
7
|
|
|
use Monolog\Logger; |
|
8
|
|
|
use org\bovigo\vfs\vfsStream; |
|
9
|
|
|
|
|
10
|
|
|
trait AbstractCommonLogTest |
|
11
|
|
|
{ |
|
12
|
|
|
private static $directoryV; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* [$logger description]. |
|
16
|
|
|
* |
|
17
|
|
|
* @var Psr\Log\LoggerInterface |
|
18
|
|
|
*/ |
|
19
|
|
|
private $logger; |
|
20
|
|
|
|
|
21
|
|
|
public static function setUpBeforeClass() |
|
22
|
|
|
{ |
|
23
|
|
|
self::$directoryV = vfsStream::setup(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->logger = new Logger('phpunit-logger'); |
|
|
|
|
|
|
29
|
|
|
$directoryLogOutput = self::$directoryV->url().'/log'; |
|
30
|
|
|
if (!file_exists($directoryLogOutput)) { |
|
31
|
|
|
mkdir($directoryLogOutput, 0700, true); |
|
32
|
|
|
} |
|
33
|
|
|
$output = "%level_name% > %message% %context% %extra%\n"; |
|
34
|
|
|
$formatter = new LineFormatter($output); |
|
35
|
|
|
$handler = new StreamHandler($directoryLogOutput.'/phpunit.log', Logger::DEBUG, true, null, false); |
|
36
|
|
|
touch($directoryLogOutput.'/phpunit.log'); |
|
37
|
|
|
$handler->setFormatter($formatter); |
|
38
|
|
|
$this->logger->pushHandler($handler); |
|
39
|
|
|
$this->logger->info('Avviato test -> '.$this->getName()); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function readLog() |
|
43
|
|
|
{ |
|
44
|
|
|
$fileLog = self::$directoryV->url().'/log/phpunit.log'; |
|
45
|
|
|
|
|
46
|
|
|
return file_get_contents($fileLog); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function tearDown() |
|
50
|
|
|
{ |
|
51
|
|
|
$fileLog = self::$directoryV->url().'/log/phpunit.log'; |
|
52
|
|
|
if ($this->hasFailed()) { |
|
|
|
|
|
|
53
|
|
|
echo "\n---- LOG ----\n"; |
|
54
|
|
|
if (is_readable($fileLog)) { |
|
55
|
|
|
echo file_get_contents($fileLog); |
|
56
|
|
|
} |
|
57
|
|
|
echo "------------\n"; |
|
58
|
|
|
} |
|
59
|
|
|
if (file_exists($fileLog)) { |
|
60
|
|
|
unlink($fileLog); |
|
61
|
|
|
} |
|
62
|
|
|
$this->logger = null; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..