Debian Codegraph @

tests/phpunit/maintenance/ManageJobsTest.php

raw symbols SCIP
1 <?php
2
3 namespace MediaWiki\Tests\Maintenance;
4
5 use ManageJobs;
6 use NullJob;
7
8 /**
9 * @covers \ManageJobs
10 * @group Database
11 * @author Dreamy Jazz
12 */
13 class ManageJobsTest extends MaintenanceBaseTestCase {
14
15 protected function getMaintenanceClass() {
16 return ManageJobs::class;
17 }
18
19 private function testCommonExecute( string $action ) {
20 $this->maintenance->setOption( 'type', 'null' );
21 $this->maintenance->setOption( 'action', $action );
22 $this->maintenance->execute();
23 }
24
25 public function testExecuteForUnknownAction() {
26 $this->expectCallToFatalError();
27 $this->expectOutputRegex( '/Invalid action.*invalidaction/' );
28 $this->testCommonExecute( 'invalidaction' );
29 }
30
31 /** @dataProvider provideJobCounts */
32 public function testExecuteForDeleteAction( $numberOfJobs ) {
33 // Create two jobs
34 $jobQueueGroup = $this->getServiceContainer()->getJobQueueGroup();
35 for ( $i = 0; $i < $numberOfJobs; $i++ ) {
36 $jobQueueGroup->push( new NullJob( [] ) );
37 }
38 $this->testCommonExecute( 'delete' );
39 // Expect that two jobs are deleted
40 $this->expectOutputRegex(
41 "/Queue has $numberOfJobs job\(s\).*deleting[\s\S]*Done; current size is 0 job\(s\)/"
42 );
43 $this->assertSame( 0, $jobQueueGroup->getQueueSizes()['null'] );
44 }
45
46 public static function provideJobCounts() {
47 return [
48 '0 jobs' => [ 0 ],
49 '2 job' => [ 2 ],
50 ];
51 }
52 }