/
SynchronizerTest.php
97 lines (76 loc) · 2.73 KB
/
SynchronizerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
use tad\FunctionMocker\FunctionMocker as Test;
class SynchronizerTest extends \PHPUnit_Framework_TestCase {
/**
* @var ELH_Synchronizer
*/
protected $sut;
protected function setUp() {
Test::setUp();
}
protected function tearDown() {
Test::tearDown();
}
/**
* @test
* it should run the first step
*/
public function it_should_run_the_first_step() {
$step = Test::replace( 'ELH_StepInterface::go' );
$sut = new ELH_Synchronizer();
$sut->set_first_step( $step );
$sut->sync();
$step->wasCalledOnce( 'go' );
}
/**
* @test
* it should set the status on the first step
*/
public function it_should_set_the_status_on_the_first_step() {
$step = Test::replace( 'ELH_StepInterface' )->method( 'set_status' )->get();
$sut = new ELH_Synchronizer();
$sut->set_first_step( $step );
$sut->sync();
$step->wasCalledWithOnce( [ Test::isInstanceOf( 'ELH_Status' ) ], 'set_status' );
}
/**
* @test
* it should capture sync exceptions and pass them to the strategy handler
*/
public function it_should_capture_sync_exceptions_and_pass_them_to_the_strategy_handler() {
$strategy = Test::replace( 'ELH_StrategyInterface' )->method( 'set' )->method( 'run' )->get();
$strategy_selector = Test::replace( 'ELH_StrategySelectorInterface' )
->method( 'get_strategy_for', $strategy )->get();
$step = Test::replace( 'ELH_StepInterface::go', function () {
throw new ELH_SyncException();
} );
$sut = new ELH_Synchronizer();
$sut->set_strategy_selector( $strategy_selector );
$sut->set_first_step( $step );
$sut->sync();
$strategy_selector->wasCalledWithOnce( [
Test::isInstanceOf( 'ELH_SyncException' ),
Test::isInstanceOf( 'ELH_StatusInterface' ),
], 'get_strategy_for' );
}
/**
* @test
* it should let the strategy selector handle the exception
*/
public function it_should_let_the_strategy_selector_handle_the_exception() {
$strategy = Test::replace( 'ELH_StrategyInterface' )->method( 'set' )->method( 'run' )->get();
$strategy_selector = Test::replace( 'ELH_StrategySelectorInterface::get_strategy_for', function () use ( $strategy ) {
return $strategy;
} );
$step = Test::replace( 'ELH_StepInterface::go', function () {
throw new ELH_SyncException();
} );
$sut = new ELH_Synchronizer();
$sut->set_strategy_selector( $strategy_selector );
$sut->set_first_step( $step );
$sut->sync();
$strategy->wasCalledWithOnce( [ 'exception', Test::isInstanceOf( 'ELH_SyncException' ) ], 'set' );
$strategy->wasCalledWithOnce( [ 'status', Test::isInstanceOf( 'ELH_StatusInterface' ) ], 'set' );
$strategy->wasCalledOnce( 'run' );
}
}