Completed
Push — master ( a83c2c...5e02ef )
by mw
86:47 queued 52:55
created

DITimeTest::testNewFromDateTime()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 29
rs 8.8571
c 1
b 0
f 0
cc 1
eloc 16
nc 1
nop 0
1
<?php
2
3
namespace SMW\Tests;
4
5
use SMWDITime as DITime;
6
7
/**
8
 * @covers \SMWDITime
9
 *
10
 * @license GNU GPL v2+
11
 * @since 2.4
12
 *
13
 * @author mwjames
14
 */
15
class DITimeTest extends \PHPUnit_Framework_TestCase {
16
17
	public function testCanConstruct() {
18
19
		$this->assertInstanceOf(
20
			'\SMWDITime',
21
			new DITime(  DITime::CM_GREGORIAN, 1970 )
22
		);
23
	}
24
25
	public function testNewFromTimestamp() {
26
27
		$instance = DITime::newFromTimestamp( '1362200400' );
28
29
		$this->assertInstanceOf(
30
			'\SMWDITime',
31
			$instance
32
		);
33
	}
34
35
	public function testNewFromDateTime() {
36
37
		$instance = DITime::newFromDateTime(
38
			new \DateTime( '2012-07-08 11:14:15.638276' )
39
		);
40
41
		$this->assertEquals(
42
			'15.638276',
43
			$instance->getSecond()
44
		);
45
46
		$instance = DITime::newFromDateTime(
47
			new \DateTime( '1582-10-04' )
48
		);
49
50
		$this->assertEquals(
51
			DITime::CM_JULIAN,
52
			$instance->getCalendarModel()
53
		);
54
55
		$instance = DITime::newFromDateTime(
56
			new \DateTime( '1582-10-05' )
57
		);
58
59
		$this->assertEquals(
60
			DITime::CM_GREGORIAN,
61
			$instance->getCalendarModel()
62
		);
63
	}
64
65
	public function testDateTimeRoundTrip() {
66
67
		$dateTime = new \DateTime( '2012-07-08 11:14:15.638276' );
68
69
		$instance = DITime::newFromDateTime(
70
			$dateTime
71
		);
72
73
		$this->assertEquals(
74
			$dateTime,
75
			$instance->asDateTime()
76
		);
77
	}
78
79
	public function testDateTimeWithLargeMs() {
80
81
		$dateTime = new \DateTime( '1300-11-02 12:03:25.888500' );
82
83
		$instance = new DITime(
84
			2, 1300, 11, 02, 12, 03, 25.888499949
0 ignored issues
show
Documentation introduced by
11 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
2 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
12 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
3 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
25.888499949 is of type double, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
		);
86
87
		$this->assertEquals(
88
			$dateTime,
89
			$instance->asDateTime()
90
		);
91
	}
92
93
	public function testDateTimeWithHistoricDate() {
94
95
		$dateTime = new \DateTime( '-0900-02-02 00:00:00' );
96
97
		$instance = new DITime(
98
			2, -900, 02, 02
0 ignored issues
show
Documentation introduced by
2 is of type integer, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
99
		);
100
101
		$this->assertEquals(
102
			$dateTime,
103
			$instance->asDateTime()
104
		);
105
	}
106
107
}
108