testSpyOnReportedMessages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
rs 9.7
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Onoi\MessageReporter\Tests\Unit;
4
5
use Onoi\MessageReporter\SpyMessageReporter;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @covers \Onoi\MessageReporter\SpyMessageReporter
10
 * @group onoi-message-reporter
11
 *
12
 * @since 1.2
13
 *
14
 * @license GNU GPL v2+
15
 * @author mwjames
16
 */
17
class SpyMessageReporterTest extends TestCase {
18
19
	public function testCanConstruct() {
20
21
		$this->assertInstanceOf(
22
			'\Onoi\MessageReporter\SpyMessageReporter',
23
			new SpyMessageReporter()
24
		);
25
	}
26
27
	public function testSpyOnReportedMessages() {
28
29
		$instance = new SpyMessageReporter();
30
		$instance->reportMessage( 'foo' );
31
32
		$this->assertEquals(
33
			[ 'foo' ],
34
			$instance->getMessages()
35
		);
36
37
		$instance->reportMessage( 'Bar' );
38
39
		$this->assertEquals(
40
			'foo, Bar',
41
			$instance->getMessagesAsString()
42
		);
43
	}
44
45
	public function testClearMessages() {
46
47
		$instance = new SpyMessageReporter();
48
		$instance->reportMessage( 'foo' );
49
50
		$this->assertNotEmpty(
51
			$instance->getMessages()
52
		);
53
54
		$instance->clearMessages();
55
56
		$this->assertEmpty(
57
			$instance->getMessages()
58
		);
59
	}
60
61
}
62