TYPO3 CMS  TYPO3_6-2
LoggerTest.php
Go to the documentation of this file.
1 <?php
3 
24 
28  public function getNameGetsLoggerName() {
29  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
30  $this->assertSame('test.core.log', $logger->getName());
31  }
32 
37  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
38  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
39  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::ERROR, $writer);
40  // warning < error, thus must not be logged
41  $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, 'test message');
42  $this->assertAttributeEmpty('records', $writer);
43  }
44 
48  public function loggerReturnsItselfAfterLogging() {
49  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
50  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
51  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::DEBUG, $writer);
52  $returnValue = $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, 'test message');
53  $this->assertInstanceOf('TYPO3\\CMS\\Core\\Log\\Logger', $returnValue);
54  }
55 
60  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
61  $returnValue = $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, 'test message');
62  $this->assertInstanceOf('TYPO3\\CMS\\Core\\Log\\Logger', $returnValue);
63  }
64 
69  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
70  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
71  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::EMERGENCY, $writer);
72  $returnValue = $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, 'test message');
73  $this->assertInstanceOf('TYPO3\\CMS\\Core\\Log\\Logger', $returnValue);
74  }
75 
79  public function loggerCallsProcessor() {
80  $component = 'test.core.log';
82  $message = 'test';
83  $logger = new \TYPO3\CMS\Core\Log\Logger($component);
85  $processor = $this->getMock('TYPO3\\CMS\\Core\\Log\\Processor\\NullProcessor', array('processLogRecord'));
86  $processor->expects($this->once())->method('processLogRecord')->will($this->returnValue(new \TYPO3\CMS\Core\Log\LogRecord($component, $level, $message)));
87  $logger->addProcessor($level, $processor);
88  // we need a writer, otherwise we will not process log records
89  $logger->addWriter($level, new \TYPO3\CMS\Core\Log\Writer\NullWriter());
90  $logger->warning($message);
91  }
92 
96  public function loggerLogsRecord() {
97  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
98  $writer = $this->getMock('TYPO3\\CMS\\Core\\Log\\Writer\\NullWriter', array('writeLog'));
99  $writer->expects($this->once())->method('writeLog');
100  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::DEBUG, $writer);
101  $logger->warning('test');
102  }
103 
108  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
109  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
110  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, $writer);
111  // notice == notice, thus must be logged
112  $logger->log(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, 'test message');
113  $this->assertAttributeNotEmpty('records', $writer);
114  }
115 
120  return array(
121  array('emergency'),
122  array('alert'),
123  array('critical'),
124  array('error'),
125  array('warning'),
126  array('notice'),
127  array('info'),
128  array('debug')
129  );
130  }
131 
137  public function loggerLogsRecordsThroughShorthandMethod($shorthandMethod) {
138  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
139  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
140  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::DEBUG, $writer);
141  call_user_func(array($logger, $shorthandMethod), 'test message');
142  $this->assertAttributeNotEmpty('records', $writer);
143  }
144 
149  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
150  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
151  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, $writer);
152  // warning > notice, thus must be logged
153  $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, 'test message');
154  $this->assertAttributeNotEmpty('records', $writer);
155  }
156 
161  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
162  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
163  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, $writer);
164  $writers = $logger->getWriters();
165  $this->assertContains($writer, $writers[\TYPO3\CMS\Core\Log\LogLevel::NOTICE]);
166  }
167 
172  $logger = new \TYPO3\CMS\Core\Log\Logger('test.core.log');
173  $writer = new \TYPO3\CMS\Core\Tests\Unit\Log\Fixtures\WriterFixture();
174  $logger->addWriter(\TYPO3\CMS\Core\Log\LogLevel::NOTICE, $writer);
175  $writers = $logger->getWriters();
176  $this->assertContains($writer, $writers[\TYPO3\CMS\Core\Log\LogLevel::EMERGENCY]);
177  }
178 
179 }
loggerLogsRecordsThroughShorthandMethod($shorthandMethod)
Definition: LoggerTest.php:137