1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MW\Logger; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Test class for \Aimeos\MW\Logger\Flow. |
14
|
|
|
*/ |
15
|
|
|
class FlowTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
private $object; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Sets up the fixture, for example, opens a network connection. |
22
|
|
|
* This method is called before a test is executed. |
23
|
|
|
* |
24
|
|
|
* @access protected |
25
|
|
|
*/ |
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
if( class_exists( '\\TYPO3\\Flow\\Log\\Logger' ) === false ) { |
29
|
|
|
$this->markTestSkipped( 'Class \\TYPO3\\Flow\\Log\\Logger not found' ); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$be = new \TYPO3\Flow\Log\Backend\FileBackend(); |
33
|
|
|
$be->setSeverityThreshold( LOG_ERR ); |
34
|
|
|
$be->setLogFileURL( 'flow.log' ); |
35
|
|
|
|
36
|
|
|
$log = new \TYPO3\Flow\Log\Logger(); |
37
|
|
|
$log->addBackend( $be ); |
38
|
|
|
|
39
|
|
|
$this->object = new \Aimeos\MW\Logger\Flow( $log ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Tears down the fixture, for example, closes a network connection. |
45
|
|
|
* This method is called after a test is executed. |
46
|
|
|
* |
47
|
|
|
* @access protected |
48
|
|
|
*/ |
49
|
|
|
protected function tearDown() |
50
|
|
|
{ |
51
|
|
|
@unlink( 'flow.log' ); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
public function testLog() |
56
|
|
|
{ |
57
|
|
|
$this->object->log( 'error' ); |
58
|
|
|
$this->assertRegExp( '/^[^ ]+ [^ ]+ [0-9]+[ ]+ERROR[ ]+MW[ ]+error/', file_get_contents( 'flow.log' ) ); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
public function testNonScalarLog() |
63
|
|
|
{ |
64
|
|
|
$this->object->log( array( 'error', 'error2', 2 ) ); |
65
|
|
|
$this->assertRegExp( '/^[^ ]+ [^ ]+ [0-9]+[ ]+ERROR[ ]+MW[ ]+\["error","error2",2\]/', file_get_contents( 'flow.log' ) ); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
public function testLogDebug() |
70
|
|
|
{ |
71
|
|
|
$this->object->log( 'debug', \Aimeos\MW\Logger\Base::DEBUG ); |
72
|
|
|
$this->assertEquals( '', file_get_contents( 'flow.log' ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
public function testBadPriority() |
77
|
|
|
{ |
78
|
|
|
$this->setExpectedException( '\\Aimeos\\MW\\Logger\\Exception' ); |
79
|
|
|
$this->object->log( 'error', -1 ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function testLogPriorityTranslate() |
84
|
|
|
{ |
85
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::EMERG ); |
86
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::ALERT ); |
87
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::CRIT ); |
88
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::ERR ); |
89
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::WARN ); |
90
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::NOTICE ); |
91
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::INFO ); |
92
|
|
|
$this->object->log( '', \Aimeos\MW\Logger\Base::DEBUG ); |
93
|
|
|
|
94
|
|
|
$content = file_get_contents( 'flow.log' ); |
95
|
|
|
$this->assertContains( 'EMERGENCY', $content ); |
96
|
|
|
$this->assertContains( 'ALERT', $content ); |
97
|
|
|
$this->assertContains( 'CRITICAL', $content ); |
98
|
|
|
$this->assertContains( 'ERROR', $content ); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: