1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace TogglJiraTest\Hydrator; |
5
|
|
|
|
6
|
|
|
use DateTimeImmutable; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use TogglJira\Entity\WorkLogEntry; |
9
|
|
|
use TogglJira\Hydrator\WorkLogHydrator; |
10
|
|
|
|
11
|
|
|
class WorkLogHydratorTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @return void |
15
|
|
|
* @throws \Exception |
16
|
|
|
*/ |
17
|
|
|
public function testHydrate(): void |
18
|
|
|
{ |
19
|
|
|
$hydrator = new WorkLogHydrator(); |
20
|
|
|
|
21
|
|
|
$data = [ |
22
|
|
|
'issueID' => 'SLR-76', |
23
|
|
|
'timeSpent' => 666, |
24
|
|
|
'comment' => 'Soldier 76, reporting for duty', |
25
|
|
|
'spentOn' => '2017-04-15T23:35:00+02:00' |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
$object = $hydrator->hydrate($data, new WorkLogEntry()); |
29
|
|
|
|
30
|
|
|
$this->assertEquals($data['issueID'], $object->getIssueID()); |
31
|
|
|
$this->assertEquals($data['timeSpent'], $object->getTimeSpent()); |
32
|
|
|
$this->assertEquals($data['comment'], $object->getComment()); |
33
|
|
|
$this->assertEquals($data['spentOn'], $object->getSpentOn()->format(DATE_ATOM)); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @return void |
38
|
|
|
* @throws \Exception |
39
|
|
|
*/ |
40
|
|
|
public function testExtract(): void |
41
|
|
|
{ |
42
|
|
|
$hydrator = new WorkLogHydrator(); |
43
|
|
|
|
44
|
|
|
$data = [ |
45
|
|
|
'issueID' => 'DVA-42', |
46
|
|
|
'timeSpent' => 9001, |
47
|
|
|
'comment' => 'Nerf this!', |
48
|
|
|
'spentOn' => new DateTimeImmutable('2017-04-15T23:50:00+02:0') |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$object = new WorkLogEntry(); |
52
|
|
|
$object->setIssueID($data['issueID']); |
53
|
|
|
$object->setTimeSpent($data['timeSpent']); |
54
|
|
|
$object->setComment($data['comment']); |
55
|
|
|
$object->setSpentOn($data['spentOn']); |
56
|
|
|
|
57
|
|
|
$expected = $hydrator->extract($object); |
58
|
|
|
|
59
|
|
|
$this->assertEquals($data, $expected); |
60
|
|
|
} |
61
|
|
|
} |