Completed
Pull Request — master (#157)
by
unknown
01:46
created

DatetimeTest::testDatetimeAbsolute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Drupal\Tests\Driver\Kernel\Drupal8\Field;
4
5
use Drupal\Tests\Driver\Kernel\Drupal8\Field\DriverFieldKernelTestBase;
6
7
/**
8
 * Tests the driver's handling of datetime fields.
9
 *
10
 * @group driver
11
 */
12
class DatetimeTest extends DriverFieldKernelTestBase
13
{
14
15
  /**
16
   * {@inheritdoc}
17
   */
18
    public static $modules = ['entity_test', 'field', 'datetime'];
19
20
  /**
21
   * Machine name of the field type being tested.
22
   *
23
   * @string
24
   */
25
    protected $fieldType = 'datetime';
26
27
  /**
28
   * Test an absolute value for a datetime field.
29
   */
30
    public function testDatetimeAbsolute()
31
    {
32
        $field = ['2015-02-10 17:45:00'];
33
        $fieldExpected = ['2015-02-10T17:45:00'];
34
        $this->assertCreatedWithField($field, $fieldExpected);
35
    }
36
37
  /**
38
   * Test a relative value in a datetime field.
39
   */
40
    public function testDatetimeRelative()
41
    {
42
        $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...
43
        $fieldExpected = ['2015-02-11T06:45:00'];
44
        $this->assertCreatedWithField($fieldExpected);
45
    }
46
47
  /**
48
   * Test an absolute value for a date-only datetime field.
49
   */
50
    public function testDateOnly()
51
    {
52
        $fieldExpected = ['2015-02-10'];
53
        $this->fieldStorageSettings = ['datetime_type' => 'date'];
54
        $this->assertCreatedWithField($fieldExpected);
55
    }
56
}
57