summaryrefslogtreecommitdiffstats
path: root/tests/Stubs/Message.php
blob: bd20d5b17817cc3f74c136d9af99ac79cfb38ebf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

/**
 * Test stub for the legacy global Message class.
 * Records errors and provides minimal API used by Util.
 */
class Message
{
	public static array $errors = [];
	public static array $warnings = [];
	public static array $infos = [];

	public static function reset(): void
	{
		self::$errors = [];
		self::$warnings = [];
	}

	public static function addError(string $key, ...$args): void
	{
		self::$errors[] = $key;
	}

	public static function addWarning(string $key, ...$args): void
	{
		self::$warnings[] = $key;
	}

	public static function hasError(string ...$keys): bool
	{
		foreach ($keys as $k) {
			if (in_array($k, self::$errors, true))
				return true;
		}
		return false;
	}

	public static function toRequest(): string
	{
		// For our tests we don't need to serialize messages.
		return '';
	}
}