summaryrefslogtreecommitdiff
path: root/tests/LoggrTest.php
blob: 2172907a28810fea0d5a01bb7c44f3a1b9f7d0ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php

namespace Asko\Loggr\Tests;

use Asko\Loggr\Drivers\OutputDriver;
use Asko\Loggr\Loggr;
use DateTime;
use PHPUnit\Framework\TestCase;

class LoggrTest extends TestCase
{
    public function testNoDriver(): void
    {
        $loggr = new Loggr();
        $loggr->info('test');
        $this->assertEquals("Driver or format not set.", $loggr->error);
    }

    public function testNoFormat(): void
    {
        $loggr = new Loggr(new OutputDriver());
        $loggr->format = null;
        $loggr->info('test');
        $this->assertEquals("Driver or format not set.", $loggr->error);
    }

    public function testInterpolation(): void
    {
        $full_date = (new DateTime())->format('Y-m-d H:i:s');
        $this->expectOutputString("[{$full_date}] LoggrTest.INFO: test something - {\"interpolation\":\"something\"}");
        $loggr = new Loggr(new OutputDriver());
        $loggr->info('test {interpolation}', ['interpolation' => 'something']);
    }

    public function testNestedInterpolation(): void
    {
        $full_date = (new DateTime())->format('Y-m-d H:i:s');
        $this->expectOutputString("[{$full_date}] LoggrTest.INFO: test something - {\"nested\":{\"interpolation\":\"something\"}}");
        $loggr = new Loggr(new OutputDriver());
        $loggr->info('test {nested.interpolation}', ['nested' => ['interpolation' => 'something']]);
    }
}