aboutsummaryrefslogtreecommitdiffstats
path: root/public/system/storage/vendor/guzzlehttp/log-subscriber/tests/SimpleLoggerTest.php
blob: 300687e7d15a514a5da9b5e02769226b3d7e8d2e (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
<?php
namespace GuzzleHttp\Tests\Subscriber\LogSubscriber;

use GuzzleHttp\Subscriber\Log\SimpleLogger;

/**
 * @covers GuzzleHttp\Subscriber\Log\SimpleLogger
 */
class SimpleLoggerTest extends \PHPUnit_Framework_TestCase
{
    public function testLogsToFopen()
    {
        $resource = fopen('php://temp', 'r+');
        $logger = new SimpleLogger($resource);
        $logger->log('WARN', 'Test');
        rewind($resource);
        $this->assertEquals("[WARN] Test\n", stream_get_contents($resource));
        fclose($resource);
    }

    public function testLogsToCallable()
    {
        $called = false;
        $c = function ($message) use (&$called) {
            $this->assertEquals("[WARN] Test\n", $message);
            $called = true;
        };
        $logger = new SimpleLogger($c);
        $logger->log('WARN', 'Test');
        $this->assertTrue($called);
    }

    public function testLogsWithEcho()
    {
        ob_start();
        $logger = new SimpleLogger();
        $logger->log('WARN', 'Test');
        $result = ob_get_clean();
        $this->assertEquals("[WARN] Test\n", $result);
    }
}