LogCallsTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testWhenThereAreNoLogCalls_getMessagesReturnsEmptyArray() 0 3 1
A testWhenMultipleThingsAreLogged_getLogMessagesReturnsAllMessages() 0 16 1
A testCanUseCollectionAsTraversable() 0 6 1
A testWhenThereAreNoLogCalls_getFirstCallReturnsNull() 0 3 1
A testWhenMultipleThingsAreLogged_getFirstCallReturnsTheFirst() 0 10 1
A testImplementsCountable() 0 9 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\PsrLogTestDoubles\Tests;
6
7
use PHPUnit\Framework\TestCase;
8
use Psr\Log\LogLevel;
9
use WMDE\PsrLogTestDoubles\LogCall;
10
use WMDE\PsrLogTestDoubles\LogCalls;
11
12
/**
13
 * @covers \WMDE\PsrLogTestDoubles\LogCalls
14
 * @covers \WMDE\PsrLogTestDoubles\LogCall
15
 *
16
 * @license GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class LogCallsTest extends TestCase {
20
21
	public function testWhenThereAreNoLogCalls_getMessagesReturnsEmptyArray() {
22
		$this->assertSame( [], ( new LogCalls() )->getMessages() );
23
	}
24
25
	public function testWhenMultipleThingsAreLogged_getLogMessagesReturnsAllMessages() {
26
		$logCalls = new LogCalls(
27
			new LogCall( LogLevel::INFO, 'And so it begins', [ 'year' => 2258 ] ),
28
			new LogCall( LogLevel::ALERT, "There's a hole in your mind" ),
29
			new LogCall( LogLevel::INFO, 'And so it begins' )
30
		);
31
32
		$this->assertSame(
33
			[
34
				'And so it begins',
35
				"There's a hole in your mind",
36
				'And so it begins'
37
			],
38
			$logCalls->getMessages()
39
		);
40
	}
41
42
	public function testCanUseCollectionAsTraversable() {
43
		$logCalls = new LogCalls( new LogCall( LogLevel::INFO, 'And so it begins' ) );
44
45
		$this->assertContains( new LogCall( LogLevel::INFO, 'And so it begins' ), $logCalls, '', false, false );
46
		$this->assertNotContains( new LogCall( LogLevel::DEBUG, 'And so it begins' ), $logCalls, '', false, false );
47
	}
48
49
	public function testWhenThereAreNoLogCalls_getFirstCallReturnsNull() {
50
		$this->assertNull( ( new LogCalls() )->getFirstCall() );
51
	}
52
53
	public function testWhenMultipleThingsAreLogged_getFirstCallReturnsTheFirst() {
54
		$logCalls = new LogCalls(
55
			new LogCall( LogLevel::INFO, 'And so it begins', [ 'year' => 2258 ] ),
56
			new LogCall( LogLevel::ALERT, "There's a hole in your mind" )
57
		);
58
59
		$this->assertSame( LogLevel::INFO, $logCalls->getFirstCall()->getLevel() );
0 ignored issues
show
Bug introduced by
The method getLevel cannot be called on $logCalls->getFirstCall() (of type array<integer,object<WMD...ogTestDoubles\LogCall>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
60
		$this->assertSame( 'And so it begins', $logCalls->getFirstCall()->getMessage() );
0 ignored issues
show
Bug introduced by
The method getMessage cannot be called on $logCalls->getFirstCall() (of type array<integer,object<WMD...ogTestDoubles\LogCall>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
61
		$this->assertSame( [ 'year' => 2258 ], $logCalls->getFirstCall()->getContext() );
0 ignored issues
show
Bug introduced by
The method getContext cannot be called on $logCalls->getFirstCall() (of type array<integer,object<WMD...ogTestDoubles\LogCall>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
62
	}
63
64
	public function testImplementsCountable() {
65
		$logCalls = new LogCalls(
66
			new LogCall( LogLevel::INFO, 'And so it begins', [ 'year' => 2258 ] ),
67
			new LogCall( LogLevel::ALERT, "There's a hole in your mind" ),
68
			new LogCall( LogLevel::INFO, 'And so it begins' )
69
		);
70
71
		$this->assertCount( 3, $logCalls );
72
	}
73
74
}
75