Test Setup Failed
Push — master ( aa9039...94c501 )
by Derek
03:32
created

testLoggerThrowsExceptionWithInvalidLogLevel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace Subreality\Dilmun\Tests\Nabu;
3
4
use Subreality\Dilmun\Nabu\LoggerHandler\File;
5
use Subreality\Dilmun\Nabu\Logger;
6
7
/**
8
 * Class LoggerTest
9
 * @package Subreality\Dilmun\Tests\Nabu
10
 */
11
class LoggerTest extends \PHPUnit_Framework_TestCase
12
{
13
    public static $full_log_location;
14
15
    /**
16
     * @var File $log_file
17
     */
18
    public static $log_file;
19
20 View Code Duplication
    public static function setUpBeforeClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        self::$full_log_location = DILMUN_LOGS_DIR . "Logger_test.log";
23
24
        if (file_exists(self::$full_log_location)) {
25
            unlink(self::$full_log_location);
26
        }
27
28
        self::$log_file = new File(self::$full_log_location);
29
        self::$log_file->initialize();
30
    }
31
32
    protected function assertPreconditions()
33
    {
34
        $this->assertFileExists(self::$full_log_location);
35
    }
36
37
    protected function setUp()
38
    {
39
        if (file_exists(self::$full_log_location)) {
40
            self::$log_file->clearFile();
41
        }
42
    }
43
44
    protected function tearDown()
45
    {
46
    }
47
48
    public static function tearDownAfterClass()
49
    {
50
        if (file_exists(self::$full_log_location)) {
51
            unlink(self::$full_log_location);
52
        }
53
    }
54
55
    public function testLogToFileWithFileHandler()
56
    {
57
        $logger = new Logger(self::$log_file);
58
59
        $returned_message = $logger->log("debug", "Logging works!");
60
61
        $logged_message = file_get_contents(self::$full_log_location);
62
63
        $this->assertContains($returned_message, $logged_message);
64
    }
65
66
    /**
67
     * @expectedException \InvalidArgumentException
68
     */
69
    public function testLoggerThrowsExceptionWithInvalidLogLevel()
70
    {
71
        $logger = new Logger(self::$log_file);
72
73
        $logger->log("this is not a valid level", "this should never be logged");
74
    }
75
76
    public function testGetHandlerReturnsHandler()
77
    {
78
        $logger = new Logger(self::$log_file);
79
80
        $handler = $logger->getHandler();
81
82
        if ($handler instanceof File) {
83
            $handler_is_file = true;
84
        } else {
85
            $handler_is_file = false;
86
        }
87
88
        $this->assertTrue($handler_is_file);
89
    }
90
}
91