LoggerSpy::getLogCalls()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\PsrLogTestDoubles;
6
7
use Psr\Log\AbstractLogger;
8
9
/**
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class LoggerSpy extends AbstractLogger {
14
15
	private $logCalls = [];
16
17
	/**
18
	 * @since 1.0
19
	 */
20 4
	public function log( $level, $message, array $context = [] ) {
21 4
		$this->logCalls[] = new LogCall( $level, $message, $context );
22 4
	}
23
24
	/**
25
	 * @since 2.0
26
	 */
27 5
	public function getLogCalls(): LogCalls {
28 5
		return new LogCalls( ...$this->logCalls );
29
	}
30
31
	/**
32
	 * @since 2.2
33
	 */
34 2
	public function getFirstLogCall(): ?LogCall {
35 2
		return $this->getLogCalls()->getFirstCall();
36
	}
37
38
	/**
39
	 * @since 1.1
40
	 * @throws AssertionException
41
	 */
42 2
	public function assertNoLoggingCallsWhereMade() {
43 2
		if ( !empty( $this->logCalls ) ) {
44 1
			throw new AssertionException(
45 1
				'Logger calls where made while non where expected: ' . var_export( $this->logCalls, true )
46
			);
47
		}
48 1
	}
49
50
}
51