Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
10 / 10 |
CRAP | |
100.00% |
1 / 1 |
BufferedRemediator | |
100.00% |
11 / 11 |
|
100.00% |
10 / 10 |
11 | |
100.00% |
1 / 1 |
redirectInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
pageNotInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
ghostPageInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
pageInWrongIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
oldVersionInIndex | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
oldDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
hasSameActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
replayOn | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
resetActions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Sanity; |
4 | |
5 | use MediaWiki\Title\Title; |
6 | use WikiPage; |
7 | |
8 | /** |
9 | * A remediator that simply records all actions scheduled to it. |
10 | * These actions can then be replayed on an arbitrary remediator by calling replayOn( Remediator ). |
11 | * The actions can be reset by calling resetActions() |
12 | */ |
13 | class BufferedRemediator implements Remediator { |
14 | private $actions = []; |
15 | |
16 | /** |
17 | * @inheritDoc |
18 | */ |
19 | public function redirectInIndex( WikiPage $page ) { |
20 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
21 | } |
22 | |
23 | /** |
24 | * @inheritDoc |
25 | */ |
26 | public function pageNotInIndex( WikiPage $page ) { |
27 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
28 | } |
29 | |
30 | /** |
31 | * @inheritDoc |
32 | */ |
33 | public function ghostPageInIndex( $docId, Title $title ) { |
34 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | */ |
40 | public function pageInWrongIndex( $docId, WikiPage $page, $indexSuffix ) { |
41 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
42 | } |
43 | |
44 | /** |
45 | * @inheritDoc |
46 | */ |
47 | public function oldVersionInIndex( $docId, WikiPage $page, $indexSuffix ) { |
48 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
49 | } |
50 | |
51 | /** |
52 | * @inheritDoc |
53 | */ |
54 | public function oldDocument( WikiPage $page ) { |
55 | $this->actions[] = [ substr( __METHOD__, strlen( __CLASS__ ) + 2 ), func_get_args() ]; |
56 | } |
57 | |
58 | /** |
59 | * The list of recorded actions |
60 | * @return array |
61 | */ |
62 | public function getActions() { |
63 | return $this->actions; |
64 | } |
65 | |
66 | /** |
67 | * Check if the actions recorded on this remediator are the same |
68 | * as the actions recorded on $remediator. |
69 | * @param BufferedRemediator $remediator |
70 | * @return bool |
71 | */ |
72 | public function hasSameActions( BufferedRemediator $remediator ) { |
73 | return $this->actions === $remediator->actions; |
74 | } |
75 | |
76 | /** |
77 | * @param Remediator $remediator |
78 | */ |
79 | public function replayOn( Remediator $remediator ) { |
80 | foreach ( $this->actions as [ $method, $args ] ) { |
81 | call_user_func_array( [ $remediator, $method ], $args ); |
82 | } |
83 | } |
84 | |
85 | /** |
86 | * Reset actions recorded by this remediator |
87 | */ |
88 | public function resetActions() { |
89 | $this->actions = []; |
90 | } |
91 | } |