Test Setup Failed
Push — test ( 8efaca...9a377f )
by Jonathan
03:08
created

MicrotimeRepresentationTest::testGetDateTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 17
rs 9.4285
1
<?php
2
3
namespace Kint\Test\Object\Representation;
4
5
use DateTime;
6
use Kint\Object\Representation\MicrotimeRepresentation;
7
use Kint\Test\KintTestCase;
8
9
class MicrotimeRepresentationTest extends KintTestCase
10
{
11
    /**
12
     * @covers \Kint\Object\Representation\MicrotimeRepresentation::__construct
13
     */
14
    public function testConstruct()
15
    {
16
        $mem = 0;
0 ignored issues
show
Unused Code introduced by
$mem 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...
17
        $mem_peak = 0;
0 ignored issues
show
Coding Style introduced by
$mem_peak does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Unused Code introduced by
$mem_peak 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...
18
19
        $r = new MicrotimeRepresentation(123, 456, 7, 8, 100);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
20
21
        $mem = memory_get_usage();
22
        $mem_peak = memory_get_peak_usage();
0 ignored issues
show
Coding Style introduced by
$mem_peak does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
23
24
        $this->assertSame(123, $r->seconds);
25
        $this->assertSame(456, $r->microseconds);
26
        $this->assertSame(7, $r->group);
27
        $this->assertSame(8, $r->lap);
28
        $this->assertSame(100, $r->total);
29
        $this->assertSame(0, $r->i);
30
        $this->assertNull($r->avg);
31
32
        $r = new MicrotimeRepresentation(123, 456, 7, 8, 100, 5);
33
        $this->assertSame(5, $r->i);
34
        $this->assertSame(20, $r->avg);
35
36
        $this->assertLessThan(1000, abs($mem - $r->mem));
37
        $this->assertSame($mem_peak, $r->mem_peak);
0 ignored issues
show
Coding Style introduced by
$mem_peak does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
38
    }
39
40
    /**
41
     * @covers \Kint\Object\Representation\MicrotimeRepresentation::getDateTime
42
     */
43
    public function testGetDateTime()
44
    {
45
        $dt = new DateTime();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $dt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
46
        $dt->setTime(0, 0, 0, 0);
47
48
        $r = new MicrotimeRepresentation($dt->format('U'), 1234, 0);
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $r. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
49
50
        $dt2 = $r->getDateTime();
51
52
        $this->assertNotEquals($dt, $dt2);
53
54
        $dt->setTime(0, 0, 0, 1234);
55
56
        $this->assertEquals($dt, $dt2);
57
58
        $this->assertSame('001234', $dt2->format('u'));
59
    }
60
}
61