ControllerBaseTest::testPageGeneration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Drupal\Tests\mongodb_watchdog\Unit;
6
7
use Drupal\mongodb_watchdog\Controller\ControllerBase;
8
use Drupal\Tests\UnitTestCase;
0 ignored issues
show
Bug introduced by
The type Drupal\Tests\UnitTestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
/**
11
 * Test the ControllerBase mechanisms.
12
 *
13
 * @coversDefaultClass \Drupal\mongodb_watchdog\Controller\ControllerBase
14
 *
15
 * @group mongodb
16
 */
17
class ControllerBaseTest extends UnitTestCase {
18
19
  const ITEMS_PER_PAGE = 50;
20
21
  /**
22
   * Test page generation for various data set shapes.
23
   *
24
   * @covers ::getPage
25
   *
26
   * @dataProvider pageGenerationData
27
   */
28
  public function testPageGeneration(int $requestedPage, int $count, int $expected): void {
29
    $actual = ControllerBase::getPage($count, $requestedPage, static::ITEMS_PER_PAGE);
30
    $this->assertEquals($expected, $actual);
31
  }
32
33
  /**
34
   * Data provider for testPageGeneration().
35
   *
36
   * @return array<int, array{0: int, 1: int, 2: int}>
37
   *   An array of page, count, result.
38
   *
39
   * @see \Drupal\Tests\mongodb_watchdog\Unit\ControllerBaseTest::testPageGeneration()
40
   *
41
   * Coding standards are ignored for the data list for the sake of readability.
42
   */
43
  public function pageGenerationData(): array {
44
    // One partial available page.
45
    $one = static::ITEMS_PER_PAGE;
46
    // Part of one page.
47
    $partial = (int) floor($one * 0.6);
48
    // More than one available page.
49
    $oneplus = $one + $partial;
50
    // Exactly two pages.
51
    $two = (int) ($one * 2);
52
    $twoplus = $two + $partial;
53
54
    $expectations = [
55
      // @codingStandardsIgnoreStart
56
      // page, count, result
57
      [-1,    0,          0],
58
      [-1,    $partial,   0],
59
      [-1,    $one,       0],
60
      [-1,    $oneplus,   0],
61
      [-1,    $two,       0],
62
63
      [ 0,    0,          0],
64
      [ 0,    $partial,   0],
65
      [ 0,    $one,       0],
66
      [ 0,    $oneplus,   0],
67
      [ 0,    $two,       0],
68
69
      [ 1,    0,          0],
70
      [ 1,    $partial,   0],
71
      [ 1,    $one,       0],
72
      [ 1,    $oneplus,   1],
73
      [ 1,    $two,       1],
74
75
      [ 2,    0,          0],
76
      [ 2,    $partial,   0],
77
      [ 2,    $one,       0],
78
      [ 2,    $oneplus,   1],
79
      [ 2,    $two,       1],
80
      [ 2,    $twoplus,   2],
81
      // @codingStandardsIgnoreEnd
82
    ];
83
    return $expectations;
84
  }
85
86
}
87