Skip to content

Commit 8a69f98

Browse files
tarrowdeer-wmde
authored andcommitted
Fix calls to deprecated version of PHPUnit providers (#990)
All PHPUnit Providers now need to be static and public[1]. This commit fixes the references to these in what I believe was the simplest way possible. In ElasticSearchIndexInitTest this meant it was necessary to move some mocking out of the provider and into the test directly. I investigated creating mocks statically; I discovered `mock()` which creates a Mockery mock but I decided that making the decision to move to a different mock library wasn't what I wanted to do here. I just wanted my tests to run without deprecation warnings. [1] sebastianbergmann/phpunit@9caafe2
1 parent 6d76222 commit 8a69f98

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

tests/Helper/ProfileValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testProfileValidatorWorksWithInvalidProfile($profile): void {
2424
$this->assertFalse($validator->passes());
2525
}
2626

27-
private function validProfileProvider() {
27+
public static function validProfileProvider() {
2828
return [
2929
['boring profile with no other' => [
3030
'purpose' => 'data_hub',
@@ -41,7 +41,7 @@ private function validProfileProvider() {
4141
];
4242
}
4343

44-
private function invalidProfileProvider() {
44+
public static function invalidProfileProvider() {
4545
return [
4646
['missing other keys' => [
4747
'purpose' => 'data_hub',

tests/Jobs/CirrusSearch/ElasticSearchIndexInitTest.php

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,30 @@ public function testJobTriggeredButNoSetting() {
142142
*
143143
* @expectedException RuntimeException
144144
*/
145-
public function testFailure($request, string $expectedFailure, $mockResponse) {
145+
public function testFailure(string $expectedFailure, $mockResponse) {
146+
$request = $this->createMock(HttpRequest::class);
147+
$mockJob = $this->createMock(Job::class);
148+
$mockJob->expects($this->once())
149+
->method('fail');
150+
151+
$request->method('execute')->willReturn(json_encode($mockResponse));
152+
153+
$job = new ElasticSearchIndexInit($this->wiki->id);
154+
$job->setJob($mockJob);
155+
$job->handle($request);
156+
157+
$this->assertSame(
158+
1,
159+
WikiSetting::where(['wiki_id' => $this->wiki->id, 'name' => WikiSetting::wwExtEnableElasticSearch, 'value' => true])->count()
160+
);
161+
}
162+
163+
public function testCurlFailure() {
164+
$expectedFailure = 'wbstackElasticSearchInit curl error for <WIKI_ID>: Scary Error!';
165+
$mockResponse = [];
166+
167+
$request = $this->createMock(HttpRequest::class);
168+
$request->method('error')->willReturn('Scary Error!');
146169
$mockJob = $this->createMock(Job::class);
147170
$mockJob->expects($this->once())
148171
->method('fail');
@@ -159,11 +182,10 @@ public function testFailure($request, string $expectedFailure, $mockResponse) {
159182
);
160183
}
161184

162-
public function failureProvider() {
185+
public static function failureProvider() {
163186

164187
$mockResponse = [];
165188
yield [
166-
$this->createMock(HttpRequest::class),
167189
'wbstackElasticSearchInit call for <WIKI_ID>. No wbstackElasticSearchInit key in response: []',
168190
$mockResponse,
169191
];
@@ -177,22 +199,12 @@ public function failureProvider() {
177199
];
178200

179201
yield [
180-
$this->createMock(HttpRequest::class),
181202
'wbstackElasticSearchInit call for <WIKI_ID> was not successful:{"warnings":[],"wbstackElasticSearchInit":{"return":0,"output":[]}}',
182203
$mockResponse,
183204
];
184205

185-
$curlError = $this->createMock(HttpRequest::class);
186-
$curlError->method('error')->willReturn('Scary Error!');
187-
yield [
188-
$curlError,
189-
'wbstackElasticSearchInit curl error for <WIKI_ID>: Scary Error!',
190-
$mockResponse,
191-
];
192-
193206
$mockResponse['wbstackElasticSearchInit']['return'] = 1;
194207
yield [
195-
$this->createMock(HttpRequest::class),
196208
'wbstackElasticSearchInit call for <WIKI_ID> was not successful:{"warnings":[],"wbstackElasticSearchInit":{"return":1,"output":[]}}',
197209
$mockResponse,
198210
];

0 commit comments

Comments
 (0)