|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\BannerServer\Tests\Unit\Entity\BannerSelection; |
|
6
|
|
|
|
|
7
|
|
|
use DateTime; |
|
8
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
|
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\Banner; |
|
11
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\Bucket; |
|
12
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\Campaign; |
|
13
|
|
|
use WMDE\BannerServer\Entity\BannerSelection\CampaignCollection; |
|
14
|
|
|
use WMDE\BannerServer\Tests\Utils\FakeRandomIntegerGenerator; |
|
15
|
|
|
|
|
16
|
|
|
#[CoversClass( CampaignCollection::class )] |
|
17
|
|
|
class CampaignCollectionTest extends TestCase { |
|
18
|
|
|
|
|
19
|
|
|
private function getTestbucket(): Bucket { |
|
20
|
|
|
return new Bucket( |
|
21
|
|
|
'test', |
|
22
|
|
|
new Banner( 'TestBanner' ) |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function test_given_date_then_returns_active_campaign(): void { |
|
27
|
|
|
$campaignCollection = new CampaignCollection( |
|
28
|
|
|
new Campaign( |
|
29
|
|
|
'C18_WMDE_Test_future', |
|
30
|
|
|
new DateTime( '2099-10-01 14:00:00' ), |
|
31
|
|
|
new DateTime( '2099-10-31 14:00:00' ), |
|
32
|
|
|
1, |
|
33
|
|
|
'default', |
|
34
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
35
|
|
|
null, |
|
36
|
|
|
null, |
|
37
|
|
|
$this->getTestbucket() |
|
38
|
|
|
), |
|
39
|
|
|
new Campaign( |
|
40
|
|
|
'C18_WMDE_Test_present', |
|
41
|
|
|
new DateTime( '2018-10-01 14:00:00' ), |
|
42
|
|
|
new DateTime( '2018-10-31 14:00:00' ), |
|
43
|
|
|
1, |
|
44
|
|
|
'default', |
|
45
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
46
|
|
|
null, |
|
47
|
|
|
null, |
|
48
|
|
|
$this->getTestbucket() |
|
49
|
|
|
), |
|
50
|
|
|
new Campaign( |
|
51
|
|
|
'C18_WMDE_Test_past', |
|
52
|
|
|
new DateTime( '1999-10-01 14:00:00' ), |
|
53
|
|
|
new DateTime( '1999-10-31 14:00:00' ), |
|
54
|
|
|
1, |
|
55
|
|
|
'default', |
|
56
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
57
|
|
|
null, |
|
58
|
|
|
null, |
|
59
|
|
|
$this->getTestbucket() |
|
60
|
|
|
) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$campaign = $campaignCollection->getCampaign( new DateTime( '2018-10-22 13:59:59' ) ); |
|
64
|
|
|
$this->assertNotNull( $campaign ); |
|
65
|
|
|
$this->assertEquals( 'C18_WMDE_Test_present', $campaign->getIdentifier() ); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function test_given_date_out_of_range_then_does_not_return_campaign(): void { |
|
69
|
|
|
$campaignCollection = new CampaignCollection( |
|
70
|
|
|
new Campaign( |
|
71
|
|
|
'C18_WMDE_Test_present', |
|
72
|
|
|
new DateTime( '2018-10-01 14:00:00' ), |
|
73
|
|
|
new DateTime( '2018-10-31 14:00:00' ), |
|
74
|
|
|
1, |
|
75
|
|
|
'default', |
|
76
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
77
|
|
|
null, |
|
78
|
|
|
null, |
|
79
|
|
|
$this->getTestbucket() |
|
80
|
|
|
), |
|
81
|
|
|
new Campaign( |
|
82
|
|
|
'C18_WMDE_Test_past', |
|
83
|
|
|
new DateTime( '1999-10-01 14:00:00' ), |
|
84
|
|
|
new DateTime( '1999-10-31 14:00:00' ), |
|
85
|
|
|
1, |
|
86
|
|
|
'default', |
|
87
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
88
|
|
|
null, |
|
89
|
|
|
null, |
|
90
|
|
|
$this->getTestbucket() |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertNull( |
|
95
|
|
|
$campaignCollection->getCampaign( new DateTime( '2017-09-01 14:00:00' ) ) |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertNull( $campaignCollection->getCampaign( new DateTime( '2017-09-01 14:00:00' ) ) ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function test_filter_function_drops_invalid_campaigns(): void { |
|
102
|
|
|
$testCampaign1 = new Campaign( |
|
103
|
|
|
'C18_WMDE_Test_present', |
|
104
|
|
|
new DateTime( '2018-10-01 14:00:00' ), |
|
105
|
|
|
new DateTime( '2018-10-31 14:00:00' ), |
|
106
|
|
|
1, |
|
107
|
|
|
'default', |
|
108
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
109
|
|
|
null, |
|
110
|
|
|
null, |
|
111
|
|
|
$this->getTestbucket() |
|
112
|
|
|
); |
|
113
|
|
|
$testCampaign2 = new Campaign( |
|
114
|
|
|
'C18_WMDE_Test_past', |
|
115
|
|
|
new DateTime( '1999-10-01 14:00:00' ), |
|
116
|
|
|
new DateTime( '1999-10-31 14:00:00' ), |
|
117
|
|
|
1, |
|
118
|
|
|
'default', |
|
119
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
120
|
|
|
null, |
|
121
|
|
|
null, |
|
122
|
|
|
$this->getTestbucket() |
|
123
|
|
|
); |
|
124
|
|
|
|
|
125
|
|
|
$campaignCollection = new CampaignCollection( |
|
126
|
|
|
$testCampaign1, |
|
127
|
|
|
$testCampaign2 |
|
128
|
|
|
); |
|
129
|
|
|
|
|
130
|
|
|
$filteredCampaignCollection = $campaignCollection->filter( |
|
131
|
|
|
static function ( Campaign $campaign ) { |
|
132
|
|
|
return $campaign->getIdentifier() === 'C18_WMDE_Test_past'; |
|
133
|
|
|
} |
|
134
|
|
|
); |
|
135
|
|
|
|
|
136
|
|
|
$this->assertSame( $testCampaign2, $filteredCampaignCollection->getFirstCampaign() ); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
public function test_given_empty_collection_then_isEmpty_results_true(): void { |
|
140
|
|
|
$emptyCampaignCollection = new CampaignCollection(); |
|
141
|
|
|
$this->assertTrue( $emptyCampaignCollection->isEmpty() ); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function test_given_non_empty_collection_then_isEmpty_results_false(): void { |
|
145
|
|
|
$nonEmptyCampaignCollection = new CampaignCollection( |
|
146
|
|
|
new Campaign( |
|
147
|
|
|
'C18_WMDE_Test_past', |
|
148
|
|
|
new DateTime( '1999-10-01 14:00:00' ), |
|
149
|
|
|
new DateTime( '1999-10-31 14:00:00' ), |
|
150
|
|
|
1, |
|
151
|
|
|
'default', |
|
152
|
|
|
new FakeRandomIntegerGenerator( 1 ), |
|
153
|
|
|
null, |
|
154
|
|
|
null, |
|
155
|
|
|
$this->getTestbucket() |
|
156
|
|
|
) |
|
157
|
|
|
); |
|
158
|
|
|
$this->assertFalse( $nonEmptyCampaignCollection->isEmpty() ); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function test_given_empty_collection_then_get_first_throws_exception(): void { |
|
162
|
|
|
$emptyCampaignCollection = new CampaignCollection(); |
|
163
|
|
|
|
|
164
|
|
|
$this->expectException( 'OutOfBoundsException' ); |
|
165
|
|
|
$emptyCampaignCollection->getFirstCampaign(); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths