Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
StaticMentorProvider | |
0.00% |
0 / 17 |
|
0.00% |
0 / 6 |
72 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
getSignupTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
newMentorFromUserIdentity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
getAutoAssignedMentors | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
getWeightedAutoAssignedMentors | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getManuallyAssignedMentors | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace GrowthExperiments\Mentorship\Provider; |
4 | |
5 | use GrowthExperiments\Mentorship\Mentor; |
6 | use InvalidArgumentException; |
7 | use MediaWiki\Title\Title; |
8 | use MediaWiki\User\UserIdentity; |
9 | |
10 | /** |
11 | * Static implementation of MentorProvider, created for use in tests |
12 | */ |
13 | class StaticMentorProvider extends MentorProvider { |
14 | |
15 | /** @var Mentor[] */ |
16 | private array $autoMentors; |
17 | |
18 | /** @var Mentor[] */ |
19 | private array $manualMentors; |
20 | |
21 | /** |
22 | * @param Mentor[] $autoMentors |
23 | * @param Mentor[] $manualMentors |
24 | */ |
25 | public function __construct( |
26 | array $autoMentors, |
27 | array $manualMentors = [] |
28 | ) { |
29 | parent::__construct(); |
30 | |
31 | $this->autoMentors = $autoMentors; |
32 | $this->manualMentors = $manualMentors; |
33 | } |
34 | |
35 | /** |
36 | * @inheritDoc |
37 | */ |
38 | public function getSignupTitle(): ?Title { |
39 | return null; |
40 | } |
41 | |
42 | /** |
43 | * @inheritDoc |
44 | */ |
45 | public function newMentorFromUserIdentity( |
46 | UserIdentity $mentorUser, ?UserIdentity $menteeUser = null |
47 | ): Mentor { |
48 | $mentors = array_merge( $this->autoMentors, $this->manualMentors ); |
49 | foreach ( $mentors as $mentor ) { |
50 | if ( $mentor->getUserIdentity()->equals( $mentorUser ) ) { |
51 | return $mentor; |
52 | } |
53 | } |
54 | throw new InvalidArgumentException( 'Invalid mentor passed' ); |
55 | } |
56 | |
57 | /** |
58 | * @inheritDoc |
59 | */ |
60 | public function getAutoAssignedMentors(): array { |
61 | return array_unique( array_values( array_map( static function ( Mentor $mentor ) { |
62 | return $mentor->getUserIdentity()->getName(); |
63 | }, $this->autoMentors ) ) ); |
64 | } |
65 | |
66 | /** |
67 | * @inheritDoc |
68 | */ |
69 | public function getWeightedAutoAssignedMentors(): array { |
70 | return $this->getAutoAssignedMentors(); |
71 | } |
72 | |
73 | /** |
74 | * @inheritDoc |
75 | */ |
76 | public function getManuallyAssignedMentors(): array { |
77 | return array_unique( array_values( array_map( static function ( Mentor $mentor ) { |
78 | return $mentor->getUserIdentity()->getName(); |
79 | }, $this->manualMentors ) ) ); |
80 | } |
81 | } |