Completed
Push — master ( 5384e5...6e7141 )
by Sam
03:02
created

TimeFrameTest::testConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Jalle19\StatusManager\Test;
4
5
use Jalle19\StatusManager\TimeFrame;
6
7
/**
8
 * Class TimeFrameTest
9
 * @package   Jalle19\StatusManager\Test
10
 * @copyright Copyright &copy; Sam Stenvall 2016-
11
 * @license   https://www.gnu.org/licenses/gpl.html The GNU General Public License v2.0
12
 */
13
class TimeFrameTest extends \PHPUnit_Framework_TestCase
14
{
15
16
	/**
17
	 * @expectedException \InvalidArgumentException
18
	 */
19
	public function testConstructor()
20
	{
21
		new TimeFrame('invalid');
22
	}
23
24
25
	/**
26
	 * A data provider can't be used since it's evaluated long before the test method is run, scewing the timestamps
27
	 */
28
	public function testGetTimestamp()
29
	{
30
		foreach ($this->timestampProvider() as $data)
31
		{
32
			$timeFrame = new TimeFrame($data[0]);
33
			$this->assertEquals($data[1], $timeFrame->getTimestamp());
34
		}
35
	}
36
37
38
	public function testJsonSerialize()
39
	{
40
		$timeFrame = new TimeFrame(TimeFrame::TIME_FRAME_ALL_TIME);
41
		$this->assertEquals(TimeFrame::TIME_FRAME_ALL_TIME, $timeFrame->jsonSerialize());
42
	}
43
44
45
	/**
46
	 * @return array
47
	 */
48
	public function timestampProvider()
49
	{
50
		return [
51
			[TimeFrame::TIME_FRAME_ALL_TIME, (new \DateTime())->getTimestamp()],
52
			[TimeFrame::TIME_FRAME_LAST_MONTH, (new \DateTime('-1 month'))->getTimestamp()],
53
			[TimeFrame::TIME_FRAME_LAST_WEEK, (new \DateTime('-1 week'))->getTimestamp()],
54
			[TimeFrame::TIME_FRAME_LAST_DAY, (new \DateTime('-1 day'))->getTimestamp()],
55
		];
56
	}
57
58
}
59