MessageReporterTestCase::getInstances()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 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