Completed
Push — 8.x-2.x ( 29896f...edd842 )
by Frédéric G.
01:56
created

ControllerBaseTest::pageGenerationData()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 29
nc 1
nop 0
dl 0
loc 40
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
namespace Drupal\mongodb_watchdog\Unit;
4
5
use Drupal\mongodb_watchdog\Controller\ControllerBase;
6
use Drupal\Tests\UnitTestCase;
7
8
/**
9
 * Test the ControllerBase mechanisms.
10
 *
11
 * @coversDefaultClass \Drupal\mongodb_watchdog\Controller\ControllerBase
12
 * @group mongodb
0 ignored issues
show
introduced by
Separate the @coversDefaultClass and @group sections by a blank line.
Loading history...
13
 */
14
class ControllerBaseTest extends UnitTestCase {
15
16
  const ITEMS_PER_PAGE = 50;
17
18
  /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
19
   * @dataProvider pageGenerationData
20
   */
21
  public function testPageGeneration(int $requestedPage, int $count, int $expected) {
22
    $actual = ControllerBase::getPage($count, $requestedPage, static::ITEMS_PER_PAGE);
23
    $this->assertEquals($expected, $actual);
24
  }
25
26
  /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
27
   * @see \Drupal\mongodb_watchdog\Unit\ControllerBaseTest::testPageGeneration()
28
   */
29
  public function pageGenerationData() {
30
    // One partial available page.
31
    $one = static::ITEMS_PER_PAGE;
32
    // Part of one page.
33
    $partial = floor($one * 0.6);
34
    // More than one available page
0 ignored issues
show
introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
35
    $oneplus = $one + $partial;
36
    // Exactly two pages.
37
    $two = $one * 2;
38
    $twoplus = $two + $partial;
39
40
    $expectations = [
41
      // page, count, result
0 ignored issues
show
introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
42
      [-1,    0,          0],
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space after "-"; 0 found
Loading history...
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 10 found
Loading history...
43
      [-1,    $partial,   0],
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space after "-"; 0 found
Loading history...
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
44
      [-1,    $one,       0],
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space after "-"; 0 found
Loading history...
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
45
      [-1,    $oneplus,   0],
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space after "-"; 0 found
Loading history...
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
46
      [-1,    $two,       0],
0 ignored issues
show
introduced by
Expected 1 space before "-"; 0 found
Loading history...
introduced by
Expected 1 space after "-"; 0 found
Loading history...
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
47
48
      [ 0,    0,          0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 10 found
Loading history...
49
      [ 0,    $partial,   0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
50
      [ 0,    $one,       0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
51
      [ 0,    $oneplus,   0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
52
      [ 0,    $two,       0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
53
54
      [ 1,    0,          0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 10 found
Loading history...
55
      [ 1,    $partial,   0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
56
      [ 1,    $one,       0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
57
      [ 1,    $oneplus,   1],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
58
      [ 1,    $two,       1],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
59
60
      [ 2,    0,          0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 10 found
Loading history...
61
      [ 2,    $partial,   0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
62
      [ 2,    $one,       0],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
63
      [ 2,    $oneplus,   1],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
64
      [ 2,    $two,       1],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 7 found
Loading history...
65
      [ 2,    $twoplus,   2],
0 ignored issues
show
introduced by
Expected one space after the comma, 4 found
Loading history...
introduced by
Expected one space after the comma, 3 found
Loading history...
66
    ];
67
    return $expectations;
68
  }
69
}
70