Completed
Push — master ( d48601...03ac5e )
by Jeroen De
13s queued 10s
created

MessageReporterTestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A reportMessageProvider() 0 18 3
A arrayWrap() 0 8 1
A testReportMessage() 0 7 2
getInstances() 0 1 ?
1
<?php
2
3
namespace Onoi\MessageReporter\Tests\Unit;
4
5
use Onoi\MessageReporter\MessageReporter;
6
use PHPUnit\Framework\TestCase;
7
8
/**
9
 * @group onoi-message-reporter
10
 *
11
 * @license GNU GPL v2+
12
 */
13
abstract class MessageReporterTestCase extends TestCase {
14
15
	/**
16
	 * Message provider, includes edge cases and random tests
17
	 *
18
	 * @return array
19
	 */
20
	public function reportMessageProvider() {
21
		$messages = [];
22
23
		$messages[] = '';
24
		$messages[] = '  ';
25
26
		foreach ( array_merge( range( 1, 100 ), [ 1000, 10000 ] ) as $length ) {
27
			$string = [];
28
29
			for ( $position = 0; $position < $length; $position++ ) {
30
				$string[] = chr( mt_rand( 32, 126 ) );
31
			}
32
33
			$messages[] = implode( '', $string );
34
		}
35
36
		return $this->arrayWrap( $messages );
37
	}
38
39
	protected function arrayWrap( array $elements ) {
40
		return array_map(
41
			function ( $element ) {
42
				return [ $element ];
43
			},
44
			$elements
45
		);
46
	}
47
48
	/**
49
	 * @dataProvider reportMessageProvider
50
	 *
51
	 * @param string $message
52
	 */
53
	public function testReportMessage( $message ) {
54
		foreach ( $this->getInstances() as $reporter ) {
55
			$reporter->reportMessage( $message );
56
			$reporter->reportMessage( $message );
57
			$this->assertTrue( true );
58
		}
59
	}
60
61
	/**
62
	 * @return MessageReporter[]
63
	 */
64
	public abstract function getInstances();
65
66
}
67