Completed
Pull Request — master (#157)
by
unknown
12:36
created

DatetimeTest::testDatetimeAbsolute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Drupal\Tests\Driver\Kernel\Drupal8\Field;
4
5
/**
6
 * Tests the driver's handling of datetime fields.
7
 *
8
 * @group driver
9
 */
10
class DatetimeTest extends DriverFieldKernelTestBase {
11
12
  /**
13
   * {@inheritdoc}
14
   */
15
  public static $modules = ['entity_test', 'field', 'datetime'];
16
17
  /**
18
   * Machine name of the field type being tested.
19
   *
20
   * @var string
21
   */
22
  protected $fieldType = 'datetime';
23
24
  /**
25
   * Test an absolute value for a datetime field.
26
   */
27
  public function testDatetimeAbsolute() {
28
    $field = ['2015-02-10 17:45:00'];
29
    $fieldExpected = ['2015-02-10T17:45:00'];
30
    $this->assertCreatedWithField($field, $fieldExpected);
31
  }
32
33
  /**
34
   * Test a relative value in a datetime field.
35
   */
36
  public function testDatetimeRelative() {
37
    $field = ['relative: 2015-02-10 17:45:00 + 1 day'];
0 ignored issues
show
Unused Code introduced by
$field is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
    $fieldExpected = ['2015-02-11T06:45:00'];
39
    $this->assertCreatedWithField($fieldExpected);
40
  }
41
42
  /**
43
   * Test an absolute value for a date-only datetime field.
44
   */
45
  public function testDateOnly() {
46
    $fieldExpected = ['2015-02-10'];
47
    $this->fieldStorageSettings = ['datetime_type' => 'date'];
48
    $this->assertCreatedWithField($fieldExpected);
49
  }
50
51
}
52