๐Ÿ“ฆ anlutro / php-multilogger

๐Ÿ“„ MultiLoggerTest.php ยท 60 lines
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60<?php
namespace anlutro\MultiLogger\Tests;

use PHPUnit_Framework_TestCase;
use Mockery as m;

use Psr\Log\LogLevel;
use anlutro\MultiLogger\MultiLogger;

class MultiLoggerTest extends PHPUnit_Framework_TestCase
{
	public function tearDown()
	{
		m::close();
	}

	public function makeMulti()
	{
		return new MultiLogger;
	}

	public function getMockLogger()
	{
		return m::mock('Psr\Log\LoggerInterface');
	}

	/** @test */
	public function logsToDefaultChannel()
	{
		$log = $this->makeMulti();
		$log->setChannel('default', $mock = $this->getMockLogger());
		$mock->shouldReceive('log')->with(LogLevel::DEBUG, 'message', [])->once();
		$log->debug('message');
	}

	/** @test */
	public function logsToSpecificChannel()
	{
		$log = $this->makeMulti();
		$log->setChannel('default', $mock = $this->getMockLogger());
		$mock->shouldReceive('log')->never();
		$mock->shouldReceive('debug')->never();
		$log->setChannel('specific', $mock = $this->getMockLogger());
		$mock->shouldReceive('debug')->with('message')->once();
		$log->to('specific')->debug('message');
	}

	/** @test */
	public function deferredChannels()
	{
		$log = $this->makeMulti();
		$log->setDeferredChannel('default', function() {
			$mock = $this->getMockLogger();
			$mock->shouldReceive('log')->with(LogLevel::DEBUG, 'message', [])->once();
			return $mock;
		});
		$log->debug('message');
	}
}