Passed
Push — 8.x-2.x ( 9af07d...3011f1 )
by Frédéric G.
05:35
created

ControllerBaseTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 64
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pageGenerationData() 0 41 1
A testPageGeneration() 0 3 1
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) {
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
   * @see \Drupal\Tests\mongodb_watchdog\Unit\ControllerBaseTest::testPageGeneration()
37
   *
38
   * Coding standards are ignored for the data list for the sake of readability.
39
   */
40
  public function pageGenerationData() {
41
    // One partial available page.
42
    $one = static::ITEMS_PER_PAGE;
43
    // Part of one page.
44
    $partial = (int) floor($one * 0.6);
45
    // More than one available page.
46
    $oneplus = $one + $partial;
47
    // Exactly two pages.
48
    $two = (int) ($one * 2);
49
    $twoplus = $two + $partial;
50
51
    $expectations = [
52
      // @codingStandardsIgnoreStart
53
      // page, count, result
54
      [-1,    0,          0],
55
      [-1,    $partial,   0],
56
      [-1,    $one,       0],
57
      [-1,    $oneplus,   0],
58
      [-1,    $two,       0],
59
60
      [ 0,    0,          0],
61
      [ 0,    $partial,   0],
62
      [ 0,    $one,       0],
63
      [ 0,    $oneplus,   0],
64
      [ 0,    $two,       0],
65
66
      [ 1,    0,          0],
67
      [ 1,    $partial,   0],
68
      [ 1,    $one,       0],
69
      [ 1,    $oneplus,   1],
70
      [ 1,    $two,       1],
71
72
      [ 2,    0,          0],
73
      [ 2,    $partial,   0],
74
      [ 2,    $one,       0],
75
      [ 2,    $oneplus,   1],
76
      [ 2,    $two,       1],
77
      [ 2,    $twoplus,   2],
78
      // @codingStandardsIgnoreEnd
79
    ];
80
    return $expectations;
81
  }
82
83
}
84