|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests\Support; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use ReflectionException; |
|
9
|
|
|
use ReflectionObject; |
|
10
|
|
|
|
|
11
|
|
|
use function str_replace; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @psalm-suppress PropertyNotSetInConstructor |
|
15
|
|
|
*/ |
|
16
|
|
|
final class Assert extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* Asserting two strings equality ignoring line endings. |
|
20
|
|
|
* |
|
21
|
|
|
* @param string $expected The expected string. |
|
22
|
|
|
* @param string $actual The actual string. |
|
23
|
|
|
* @param string $message The message to display if the assertion fails. |
|
24
|
|
|
*/ |
|
25
|
|
|
public static function equalsWithoutLE(string $expected, string $actual, string $message = ''): void |
|
26
|
|
|
{ |
|
27
|
|
|
$expected = str_replace("\r\n", "\n", $expected); |
|
28
|
|
|
$actual = str_replace("\r\n", "\n", $actual); |
|
29
|
|
|
|
|
30
|
|
|
self::assertEquals($expected, $actual, $message); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Invokes an inaccessible method. |
|
35
|
|
|
* |
|
36
|
|
|
* @param object $object The object to invoke the method on. |
|
37
|
|
|
* @param string $method The name of the method to invoke. |
|
38
|
|
|
* @param array $args The arguments to pass to the method. |
|
39
|
|
|
* |
|
40
|
|
|
* @throws ReflectionException |
|
41
|
|
|
*/ |
|
42
|
|
|
public static function invokeMethod(object $object, string $method, array $args = []): mixed |
|
43
|
|
|
{ |
|
44
|
|
|
$reflection = new ReflectionObject($object); |
|
45
|
|
|
$method = $reflection->getMethod($method); |
|
46
|
|
|
$method->setAccessible(true); |
|
47
|
|
|
|
|
48
|
|
|
return $method->invokeArgs($object, $args); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|