Completed
Push — master ( 50ef2b...3bc0ea )
by Shcherbak
05:22
created

LineEndingReviewTest::testReviewInvalidLines()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 17
rs 9.4285
cc 2
eloc 11
nc 2
nop 2
1
<?php
2
3
  namespace Funivan\Cs\Tools\Tests\LineEnding;
4
5
  use Funivan\Cs\FileProcessor\FileTool;
6
  use Funivan\Cs\Tools\LineEnding\LineEndingReview;
7
  use Tests\Funivan\Cs\ReviewTestCase;
8
9
  /**
10
   *
11
   */
12
  class LineEndingReviewTest extends ReviewTestCase {
13
14
    /**
15
     * @return FileTool
16
     */
17
    public function getTool() {
18
      return new LineEndingReview();
19
    }
20
21
22
    /**
23
     * @return array
24
     */
25
    public function getReplaceSpacesDataProvider() {
26
      return [
27
        [
28
          'code' => '<?php\n 
29
  echo 1;\r',
30
          'lines' => [2],
31
        ],
32
        [
33
          'code' => '<?php echo 1;',
34
          'lines' => [],
35
        ],
36
        [
37
          'code' => '<?php\r\n
38
          echo 1;\n
39
          \r',
40
          'lines' => [1, 2],
41
        ],
42
        [
43
          'code' => '<?php\n
44
\r\n
45
\r\n',
46
          'lines' => [2],
47
48
        ],
49
      ];
50
    }
51
52
53
    /**
54
     * @dataProvider getReplaceSpacesDataProvider
55
     * @param string $input
56
     * @param array $expectErrorLines
57
     */
58
    public function testReviewInvalidLines($input, array $expectErrorLines) {
59
      $map = [
60
        '\r' => "\r",
61
        '\n' => "\n",
62
      ];
63
64
      $input = str_replace("\n", '', $input);
65
      $input = strtr($input, $map);
66
67
      $report = $this->process($input);
68
      $errorLines = [];
69
      foreach ($report as $message) {
70
        $errorLines[] = $message->getLine();
71
      }
72
73
      $this->assertEquals($expectErrorLines, $errorLines);
74
    }
75
76
  }
77