‪TYPO3CMS  11.5
LogLevelTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use Psr\Log\InvalidArgumentException;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪LogLevelTest extends UnitTestCase
28 {
32  public function ‪isValidLevelValidatesValidLevels(): void
33  {
34  $validLevels = [0, 1, 2, 3, 4, 5, 6, 7];
35  foreach ($validLevels as $validLevel) {
36  self::assertTrue(‪LogLevel::isValidLevel($validLevel));
37  }
38  }
39 
44  {
45  $invalidLevels = [-1, 8];
46  foreach ($invalidLevels as $invalidLevel) {
47  self::assertFalse(‪LogLevel::isValidLevel($invalidLevel));
48  }
49  }
50 
55  {
56  return [
57  'negative integer' => [-1],
58  'higher level than expected' => [8],
59  ];
60  }
61 
67  {
68  $this->expectException(InvalidArgumentException::class);
69  $this->expectExceptionCode(1321637121);
70 
71  ‪LogLevel::validateLevel($inputValue);
72  }
73 
78  {
79  self::assertEquals(7, ‪LogLevel::normalizeLevel('debug'));
80  }
81 
83  {
84  return [
85  'debug and up' => [
86  LogLevel::DEBUG,
87  [
88  'emergency',
89  'alert',
90  'critical',
91  'error',
92  'warning',
93  'notice',
94  'info',
95  'debug',
96  ],
97  ],
98  'error and up' => [
99  LogLevel::ERROR,
100  [
101  'emergency',
102  'alert',
103  'critical',
104  'error',
105  ],
106  ],
107  'emergency only' => [
108  LogLevel::EMERGENCY,
109  [
110  'emergency',
111  ],
112  ],
113  ];
114  }
115 
120  public function ‪atLeastReturnsCorrectListOfLevels(string $level, array $expected): void
121  {
122  self::assertSame($expected, ‪LogLevel::atLeast($level));
123  }
124 }
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\isValidLevelDoesNotValidateInvalidLevels
‪isValidLevelDoesNotValidateInvalidLevels()
Definition: LogLevelTest.php:43
‪TYPO3\CMS\Core\Log\LogLevel\validateLevel
‪static validateLevel(int $level)
Definition: LogLevel.php:81
‪TYPO3\CMS\Core\Tests\Unit\Log
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\normalizeLevelConvertsValidLevelFromStringToInteger
‪normalizeLevelConvertsValidLevelFromStringToInteger()
Definition: LogLevelTest.php:77
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest
Definition: LogLevelTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\atLeastReturnsCorrectListOfLevels
‪atLeastReturnsCorrectListOfLevels(string $level, array $expected)
Definition: LogLevelTest.php:120
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\atLeastReturnsCorrectListOfLevelsDataProvider
‪atLeastReturnsCorrectListOfLevelsDataProvider()
Definition: LogLevelTest.php:82
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider
‪isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSoDataProvider()
Definition: LogLevelTest.php:54
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo
‪isValidLevelThrowsExceptionOnInvalidLevelIfAskedToDoSo($inputValue)
Definition: LogLevelTest.php:66
‪TYPO3\CMS\Core\Log\LogLevel\atLeast
‪static array< string > atLeast($level)
Definition: LogLevel.php:112
‪TYPO3\CMS\Core\Log\LogLevel\normalizeLevel
‪static int normalizeLevel($level)
Definition: LogLevel.php:94
‪TYPO3\CMS\Core\Tests\Unit\Log\LogLevelTest\isValidLevelValidatesValidLevels
‪isValidLevelValidatesValidLevels()
Definition: LogLevelTest.php:32
‪TYPO3\CMS\Core\Log\LogLevel
Definition: LogLevel.php:24
‪TYPO3\CMS\Core\Log\LogLevel\isValidLevel
‪static bool isValidLevel(int $level)
Definition: LogLevel.php:70