1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ddeboer\DataImport\Tests; |
4
|
|
|
|
5
|
|
|
use Ddeboer\DataImport\Result; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Tests For Workflow Result |
9
|
|
|
* |
10
|
|
|
* @author Aydin Hassan <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class ResultTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
public function testResultName() |
15
|
|
|
{ |
16
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage()); |
17
|
|
|
$this->assertSame('export', $result->getName()); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function testResultCounts() |
21
|
|
|
{ |
22
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage()); |
23
|
|
|
$this->assertSame(10, $result->getTotalProcessedCount()); |
24
|
|
|
$this->assertSame(10, $result->getSuccessCount()); |
25
|
|
|
$this->assertSame(0, $result->getErrorCount()); |
26
|
|
|
|
27
|
|
|
$exceptions = new \SplObjectStorage(); |
28
|
|
|
$exceptions->attach(new \Exception()); |
29
|
|
|
$exceptions->attach(new \Exception()); |
30
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions); |
31
|
|
|
$this->assertSame(10, $result->getTotalProcessedCount()); |
32
|
|
|
$this->assertSame(8, $result->getSuccessCount()); |
33
|
|
|
$this->assertSame(2, $result->getErrorCount()); |
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testDates() |
38
|
|
|
{ |
39
|
|
|
$startDate = new \DateTime("22-07-2014 22:00"); |
40
|
|
|
$endDate = new \DateTime("22-07-2014 23:30"); |
41
|
|
|
|
42
|
|
|
$result = new Result('export', $startDate, $endDate, 10, new \SplObjectStorage()); |
43
|
|
|
|
44
|
|
|
$this->assertSame($startDate, $result->getStartTime()); |
45
|
|
|
$this->assertSame($endDate, $result->getEndTime()); |
46
|
|
|
$this->assertInstanceOf('DateInterval', $result->getElapsed()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testMicroElapsed() |
50
|
|
|
{ |
51
|
|
|
$startDate = new \DateTime('2016-07-12 20:51:42.805421'); |
52
|
|
|
$endDate = new \DateTime('2016-07-12 20:51:42.841276'); |
53
|
|
|
$microElapsed = abs($endDate->format('u') - $startDate->format('u')); |
54
|
|
|
|
55
|
|
|
$result = new Result('export', $startDate, $endDate, 10, new \SplObjectStorage()); |
56
|
|
|
$this->assertSame($microElapsed, $result->getMicroElapsed()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHasErrorsReturnsTrueIfAnyExceptions() |
60
|
|
|
{ |
61
|
|
|
$exceptions = new \SplObjectStorage(); |
62
|
|
|
$exceptions->attach(new \Exception()); |
63
|
|
|
$exceptions->attach(new \Exception()); |
64
|
|
|
|
65
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions); |
66
|
|
|
$this->assertTrue($result->hasErrors()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testHasErrorsReturnsFalseIfNoExceptions() |
70
|
|
|
{ |
71
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage()); |
72
|
|
|
$this->assertFalse($result->hasErrors()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetExceptions() |
76
|
|
|
{ |
77
|
|
|
$exceptions = new \SplObjectStorage(); |
78
|
|
|
$exceptions->attach(new \Exception()); |
79
|
|
|
$exceptions->attach(new \Exception()); |
80
|
|
|
|
81
|
|
|
$result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions); |
82
|
|
|
$this->assertSame($exceptions, $result->getExceptions()); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|