1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Maketok\DataMigration\Workflow; |
4
|
|
|
|
5
|
|
|
class ResultTest extends \PHPUnit_Framework_TestCase |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var Result |
9
|
|
|
*/ |
10
|
|
|
private $result; |
|
|
|
|
11
|
|
|
|
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
$this->result = new Result(); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @test |
19
|
|
|
*/ |
20
|
|
|
public function testGetAllErrors() |
21
|
|
|
{ |
22
|
|
|
$this->result->addActionError('test_action', 'Error message1'); |
23
|
|
|
$this->result->addActionError('test_action2', 'Error message2'); |
24
|
|
|
$this->result->addActionError('test_action3', 'Error message1'); |
25
|
|
|
$this->result->addActionError('test_action3', 'Error message2'); |
26
|
|
|
$this->assertSame([ |
27
|
|
|
'Error message1', |
28
|
|
|
'Error message2', |
29
|
|
|
'Error message1', |
30
|
|
|
'Error message2', |
31
|
|
|
], $this->result->getAllErrors()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @test |
36
|
|
|
*/ |
37
|
|
|
public function testGetAllExceptions() |
38
|
|
|
{ |
39
|
|
|
$e1 = new \Exception('bar'); |
|
|
|
|
40
|
|
|
$e2 = new \Exception('baz'); |
|
|
|
|
41
|
|
|
$e3 = new \Exception('zap'); |
|
|
|
|
42
|
|
|
$this->result->addActionException('test_action', $e1); |
43
|
|
|
$this->result->addActionException('test_action2', $e2); |
44
|
|
|
$this->result->addActionException('test_action2', $e3); |
45
|
|
|
$this->assertEquals([$e1, $e2, $e3], $this->result->getAllExceptions()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @test |
50
|
|
|
*/ |
51
|
|
|
public function testGetParticipants() |
52
|
|
|
{ |
53
|
|
|
$start1 = new \DateTime(); |
54
|
|
|
$end2 = new \DateTime(); |
55
|
|
|
$e = new \Exception(); |
|
|
|
|
56
|
|
|
$this->result->setActionStartTime('test1', $start1); |
57
|
|
|
$this->result->setActionEndTime('test2', $end2); |
58
|
|
|
$this->result->addActionError('test3', 'error'); |
59
|
|
|
$this->result->addActionException('test2', $e); |
60
|
|
|
$this->result->addActionError('test2', 'err'); |
61
|
|
|
$this->result->incrementActionProcessed('test4'); |
62
|
|
|
$this->result->incrementActionProcessed('test2'); |
63
|
|
|
|
64
|
|
|
$this->assertEquals([ |
65
|
|
|
'test1' => [ |
66
|
|
|
'start_time' => $start1, |
67
|
|
|
], |
68
|
|
|
'test2' => [ |
69
|
|
|
'end_time' => $end2, |
70
|
|
|
'exceptions' => [$e], |
71
|
|
|
'errors' => ['err'], |
72
|
|
|
'rows_processed' => 1, |
73
|
|
|
], |
74
|
|
|
'test3' => [ |
75
|
|
|
'errors' => ['error'], |
76
|
|
|
], |
77
|
|
|
'test4' => [ |
78
|
|
|
'rows_processed' => 1, |
79
|
|
|
], |
80
|
|
|
], $this->result->getParticipants()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
*/ |
86
|
|
|
public function testGetTotalRowsProcessed() |
87
|
|
|
{ |
88
|
|
|
$this->result->incrementActionProcessed('test4', 1); |
89
|
|
|
$this->result->incrementActionProcessed('test1', 100); |
90
|
|
|
|
91
|
|
|
$this->assertSame(101, $this->result->getTotalRowsProcessed()); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @test |
96
|
|
|
*/ |
97
|
|
|
public function testGetTotalRowsThrough() |
98
|
|
|
{ |
99
|
|
|
$this->result->incrementActionProcessed('test4', 1); |
100
|
|
|
$this->result->incrementActionProcessed('test1', 100); |
101
|
|
|
$this->result->incrementActionProcessed('test1', 1); |
102
|
|
|
|
103
|
|
|
$this->assertSame(1, $this->result->getTotalRowsThrough()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
*/ |
109
|
|
|
public function testGetTimes() |
110
|
|
|
{ |
111
|
|
|
$dt = new \DateTime(); |
|
|
|
|
112
|
|
|
$dt2 = new \DateTime('+1 minute'); |
113
|
|
|
$this->result->setStartTime($dt); |
114
|
|
|
$this->result->setEndTime($dt2); |
115
|
|
|
$this->result->setActionStartTime('test', $dt); |
116
|
|
|
$this->result->setActionEndTime('test', $dt2); |
117
|
|
|
$this->result->setActionStartTime('test', $dt2); |
118
|
|
|
$this->result->setActionEndTime('test', $dt); |
119
|
|
|
|
120
|
|
|
$this->assertSame($dt, $this->result->getStartTime()); |
121
|
|
|
$this->assertSame($dt2, $this->result->getEndTime()); |
122
|
|
|
$this->assertSame($dt2, $this->result->getActionStartTime('test')); |
123
|
|
|
$this->assertSame($dt, $this->result->getActionEndTime('test')); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @test |
128
|
|
|
*/ |
129
|
|
|
public function testGetErrors() |
130
|
|
|
{ |
131
|
|
|
$this->assertEquals([], $this->result->getActionErrors('test')); |
132
|
|
|
$this->assertEquals([], $this->result->getActionExceptions('test')); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|