|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Queryr\Replicator\Importer; |
|
4
|
|
|
|
|
5
|
|
|
use Exception; |
|
6
|
|
|
use PHPUnit\Framework\TestCase; |
|
7
|
|
|
use Queryr\Replicator\Importer\ImportStats; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @covers \Queryr\Replicator\Importer\ImportStats |
|
11
|
|
|
* |
|
12
|
|
|
* @licence GNU GPL v2+ |
|
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
|
14
|
|
|
*/ |
|
15
|
|
|
class ImportStatsTest extends TestCase { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var ImportStats |
|
19
|
|
|
*/ |
|
20
|
|
|
private $stats; |
|
21
|
|
|
|
|
22
|
|
|
public function setUp() { |
|
23
|
|
|
$this->stats = new ImportStats(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testWhenNothingIsRecorded_getCountReturnsZero() { |
|
27
|
|
|
$this->assertEquals( 0, $this->stats->getEntityCount() ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testBothSuccessAndFailureAddsToCount() { |
|
31
|
|
|
$this->stats->recordSuccess(); |
|
32
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
33
|
|
|
$this->stats->recordSuccess(); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals( 3, $this->stats->getEntityCount() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testOnlyFailureAddsToFailureCount() { |
|
39
|
|
|
$this->stats->recordSuccess(); |
|
40
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
41
|
|
|
$this->stats->recordSuccess(); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertEquals( 1, $this->stats->getErrorCount() ); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testOnlySuccessAddsToSuccessCount() { |
|
47
|
|
|
$this->stats->recordSuccess(); |
|
48
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
49
|
|
|
$this->stats->recordSuccess(); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals( 2, $this->stats->getSuccessCount() ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testWhenThereAreNoErrors_errorRatioIsZero() { |
|
55
|
|
|
$this->stats->recordSuccess(); |
|
56
|
|
|
$this->stats->recordSuccess(); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals( 0, $this->stats->getErrorRatio() ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testWhenThereAreNoEntities_errorRatioIsZero() { |
|
62
|
|
|
$this->assertEquals( 0, $this->stats->getErrorRatio() ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testWhenThereAreOnlyErrors_errorRatioIsOneHundred() { |
|
66
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
67
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertEquals( 100, $this->stats->getErrorRatio() ); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function testErrorRatio() { |
|
73
|
|
|
$this->stats->recordSuccess(); |
|
74
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
75
|
|
|
$this->stats->recordError( new Exception( 'not enough kittens' ) ); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertEquals( 2 / 3 * 100, $this->stats->getErrorRatio() ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|