Passed
Pull Request — master (#32)
by Dmitriy
06:55
created

assertEqualStringsIgnoringLineEndings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Test\Support;
6
7
trait PHPUnitAssertTrait
8
{
9 12
    public function assertEqualStringsIgnoringLineEndings(
10
        string $expected,
11
        string $actual,
12
        string $message = ''
13
    ): void {
14 12
        $expected = self::normalizeLineEndings($expected);
0 ignored issues
show
Bug Best Practice introduced by
The method Yiisoft\Test\Support\PHP...:normalizeLineEndings() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
        /** @scrutinizer ignore-call */ 
15
        $expected = self::normalizeLineEndings($expected);
Loading history...
15 12
        $actual = self::normalizeLineEndings($actual);
16
17 12
        $this->assertEquals($expected, $actual, $message);
0 ignored issues
show
Bug introduced by
It seems like assertEquals() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        $this->/** @scrutinizer ignore-call */ 
18
               assertEquals($expected, $actual, $message);
Loading history...
18 9
    }
19
20 3
    public function assertStringContainsStringIgnoringLineEndings(
21
        string $needle,
22
        string $haystack,
23
        string $message = ''
24
    ): void {
25 3
        $needle = self::normalizeLineEndings($needle);
0 ignored issues
show
Bug Best Practice introduced by
The method Yiisoft\Test\Support\PHP...:normalizeLineEndings() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

25
        /** @scrutinizer ignore-call */ 
26
        $needle = self::normalizeLineEndings($needle);
Loading history...
26 3
        $haystack = self::normalizeLineEndings($haystack);
27
28 3
        $this->assertStringContainsString($needle, $haystack, $message);
0 ignored issues
show
Bug introduced by
The method assertStringContainsString() does not exist on Yiisoft\Test\Support\PHPUnitAssertTrait. Did you maybe mean assertStringContainsStringIgnoringLineEndings()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        $this->/** @scrutinizer ignore-call */ 
29
               assertStringContainsString($needle, $haystack, $message);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29 2
    }
30
31 15
    private function normalizeLineEndings(string $value): string
32
    {
33 15
        return strtr($value, [
34 15
            "\r\n" => "\n",
35
            "\r" => "\n",
36
        ]);
37
    }
38
}
39