1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 10/1/17 |
7
|
|
|
* Time: 11:03 AM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Tests\Unit\Helpers; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Tfboe\FmLib\Helpers\Logging; |
14
|
|
|
use Tfboe\FmLib\Helpers\Logs; |
15
|
|
|
use Tfboe\FmLib\Tests\Helpers\UnitTestCase; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class BasicEnumTest |
20
|
|
|
* @package Tfboe\FmLib\TestHelpers |
21
|
|
|
*/ |
22
|
|
|
class LoggingTest extends UnitTestCase |
23
|
|
|
{ |
24
|
|
|
//<editor-fold desc="Public Methods"> |
25
|
|
|
/** |
26
|
|
|
* Clears the testing log |
27
|
|
|
* @before |
28
|
|
|
*/ |
29
|
|
|
public function clearLog() |
30
|
|
|
{ |
31
|
|
|
$path = sys_get_temp_dir() . '/logs/' . Logs::TESTING . '.log'; |
32
|
|
|
if (is_writeable($path)) { |
33
|
|
|
unlink($path); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @covers \Tfboe\FmLib\Helpers\Logging::log |
39
|
|
|
* @uses \Tfboe\FmLib\Helpers\BasicEnum |
40
|
|
|
*/ |
41
|
|
|
public function testLog() |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @return string |
45
|
|
|
*/ |
46
|
|
|
function storage_path_function() |
47
|
|
|
{ |
48
|
|
|
return sys_get_temp_dir(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
; |
52
|
|
|
|
53
|
|
|
Logging::$storagePathFunction = 'Tfboe\FmLib\Tests\Unit\Helpers\storage_path_function'; |
54
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
55
|
|
|
Logging::log("invalid", "INVALID LOG"); |
56
|
|
|
/** @noinspection PhpUnhandledExceptionInspection */ |
57
|
|
|
Logging::log("testMessage", Logs::TESTING); |
58
|
|
|
$path = sys_get_temp_dir() . '/logs/' . Logs::TESTING . '.log'; |
59
|
|
|
self::assertTrue(is_writable($path)); |
60
|
|
|
self::assertRegExp('/^\\[[2-9][0-9]{3}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\\] testing\\.INFO: ' . |
61
|
|
|
'testMessage \\[\\] \\[\\]\\n$/', file_get_contents($path)); |
62
|
|
|
Logging::$storagePathFunction = 'storage_path'; |
63
|
|
|
} |
64
|
|
|
//</editor-fold desc="Public Methods"> |
65
|
|
|
} |