Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / maintenance / ManageJobsTest.php
blob7f3e0541d901d6a5b1cddfd8cdb2a35e7c059a17
1 <?php
3 namespace MediaWiki\Tests\Maintenance;
5 use ManageJobs;
6 use NullJob;
8 /**
9 * @covers \ManageJobs
10 * @group Database
11 * @author Dreamy Jazz
13 class ManageJobsTest extends MaintenanceBaseTestCase {
15 protected function getMaintenanceClass() {
16 return ManageJobs::class;
19 private function testCommonExecute( string $action ) {
20 $this->maintenance->setOption( 'type', 'null' );
21 $this->maintenance->setOption( 'action', $action );
22 $this->maintenance->execute();
25 public function testExecuteForUnknownAction() {
26 $this->expectCallToFatalError();
27 $this->expectOutputRegex( '/Invalid action.*invalidaction/' );
28 $this->testCommonExecute( 'invalidaction' );
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( [] ) );
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\)/"
43 $this->assertSame( 0, $jobQueueGroup->getQueueSizes()['null'] );
46 public static function provideJobCounts() {
47 return [
48 '0 jobs' => [ 0 ],
49 '2 job' => [ 2 ],