TimeFrameTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 13
c 3
b 0
f 1
dl 0
loc 40
rs 10
wmc 5

4 Methods

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