|
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; |
|
|
|
|
|
|
17
|
|
|
$mem_peak = 0; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
$r = new MicrotimeRepresentation(123, 456, 7, 8, 100); |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
$mem = memory_get_usage(); |
|
22
|
|
|
$mem_peak = memory_get_peak_usage(); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @covers \Kint\Object\Representation\MicrotimeRepresentation::getDateTime |
|
42
|
|
|
*/ |
|
43
|
|
|
public function testGetDateTime() |
|
44
|
|
|
{ |
|
45
|
|
|
$dt = new DateTime(); |
|
|
|
|
|
|
46
|
|
|
$dt->setTime(0, 0, 0, 0); |
|
47
|
|
|
|
|
48
|
|
|
$r = new MicrotimeRepresentation($dt->format('U'), 1234, 0); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.