TYPO3 CMS  TYPO3_6-2
LogRecordTest.php
Go to the documentation of this file.
1 <?php
3 
23 
30  protected function getRecord(array $parameters = array()) {
32  $record = new \TYPO3\CMS\Core\Log\LogRecord($parameters['component'] ?: 'test.core.log', $parameters['level'] ?: \TYPO3\CMS\Core\Log\LogLevel::DEBUG, $parameters['message'] ?: 'test message', $parameters['data'] ?: array());
33  return $record;
34  }
35 
39  public function constructorSetsCorrectComponent() {
40  $component = 'test.core.log';
41  $record = $this->getRecord(array('component' => $component));
42  $this->assertEquals($component, $record->getComponent());
43  }
44 
48  public function constructorSetsCorrectLogLevel() {
50  $record = $this->getRecord(array('level' => $logLevel));
51  $this->assertEquals($logLevel, $record->getLevel());
52  }
53 
57  public function constructorSetsCorrectMessage() {
58  $logMessage = 'test message';
59  $record = $this->getRecord(array('message' => $logMessage));
60  $this->assertEquals($logMessage, $record->getMessage());
61  }
62 
66  public function constructorSetsCorrectData() {
67  $dataArray = array(
68  'foo' => 'bar'
69  );
70  $record = $this->getRecord(array('data' => $dataArray));
71  $this->assertEquals($dataArray, $record->getData());
72  }
73 
77  public function setComponentSetsComponent() {
78  $record = $this->getRecord();
79  $component = 'testcomponent';
80  $this->assertEquals($component, $record->setComponent($component)->getComponent());
81  }
82 
86  public function setLevelSetsLevel() {
87  $record = $this->getRecord();
89  $this->assertEquals($level, $record->setLevel($level)->getLevel());
90  }
91 
96  public function setLevelValidatesLevel() {
97  $record = $this->getRecord();
98  $record->setLevel(100);
99  }
100 
104  public function setMessageSetsMessage() {
105  $record = $this->getRecord();
106  $message = 'testmessage';
107  $this->assertEquals($message, $record->setMessage($message)->getMessage());
108  }
109 
113  public function setCreatedSetsCreated() {
114  $record = $this->getRecord();
115  $created = 123.45;
116  $this->assertEquals($created, $record->setCreated($created)->getCreated());
117  }
118 
122  public function setRequestIdSetsRequestId() {
123  $record = $this->getRecord();
124  $requestId = 'testrequestid';
125  $this->assertEquals($requestId, $record->setRequestId($requestId)->getRequestId());
126  }
127 
131  public function toArrayReturnsCorrectValues() {
132  $component = 'test.core.log';
134  $message = 'test message';
135  $data = array('foo' => 'bar');
137  $record = new \TYPO3\CMS\Core\Log\LogRecord($component, $level, $message, $data);
138  $recordArray = $record->toArray();
139  $this->assertEquals($component, $recordArray['component']);
140  $this->assertEquals($level, $recordArray['level']);
141  $this->assertEquals($message, $recordArray['message']);
142  $this->assertEquals($data, $recordArray['data']);
143  }
144 
148  public function toStringIncludesDataAsJson() {
149  $dataArray = array('foo' => 'bar');
150  $record = $this->getRecord(array('data' => $dataArray));
151  $this->assertContains(json_encode($dataArray), (string) $record);
152  }
153 
158  $dataArray = array('exception' => new \Exception('foo'));
159  $record = $this->getRecord(array('data' => $dataArray));
160  // Since 7.0.0-dev 17.05.2015 the output of Exception is changed.
161  // https://github.com/php/php-src/commit/3ae995f03c8f60c4a4c9718262545cf5a6a08da3
162  // To check for dev version we need to compare with a version before 7.0.0
163  if (version_compare(PHP_VERSION, '6.99.00') >= 0) {
164  $this->assertContains('Exception: foo', (string)$record);
165  } else {
166  $this->assertContains('\'Exception\' with message \'foo\'', (string)$record);
167  }
168  }
169 
170 }
$parameters
Definition: FileDumpEID.php:15