Assert   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A equalsWithoutLE() 0 6 1
A invokeMethod() 0 7 1
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