3 namespace MediaWiki\Tests\Maintenance
;
5 use MediaWiki\Json\FormatJson
;
14 class RunJobsTest
extends MaintenanceBaseTestCase
{
16 protected function getMaintenanceClass() {
17 return RunJobs
::class;
20 public function testExecuteWhenNoJobsQueued() {
21 $this->maintenance
->execute();
22 $this->expectOutputString( "Job queue is empty.\n" );
25 public function testExecuteWhenNoJobsQueuedAndJsonOutput() {
26 $this->maintenance
->setOption( 'result', 'json' );
27 $this->maintenance
->execute();
28 $output = $this->getActualOutputForAssertion();
29 $outputAsArray = FormatJson
::decode( $output, true );
30 $this->assertSame( 'none-ready', $outputAsArray['reached'] );
31 $this->assertCount( 0, $outputAsArray['jobs'] );
34 public function testExecuteForQueuedJob() {
35 $this->getServiceContainer()->getJobQueueGroup()
36 ->push( new NullJob( [] ) );
37 $this->maintenance
->setOption( 'result', 'json' );
38 $this->maintenance
->execute();
39 $output = $this->getActualOutputForAssertion();
40 $outputAsArray = FormatJson
::decode( $output, true );
41 $this->assertSame( 'none-ready', $outputAsArray['reached'] );
42 $this->assertCount( 1, $outputAsArray['jobs'] );
43 $this->assertSame( 'null', $outputAsArray['jobs'][0]['type'] );
44 $this->assertSame( 'ok', $outputAsArray['jobs'][0]['status'] );
47 public function testExecuteForQueuedJobsAndReachesJobLimit() {
48 $this->getServiceContainer()->getJobQueueGroup()
49 ->push( new NullJob( [ 'lives' => 100 ] ) );
50 $this->maintenance
->setOption( 'result', 'json' );
51 $this->maintenance
->setOption( 'maxjobs', 3 );
52 $this->maintenance
->execute();
53 $output = $this->getActualOutputForAssertion();
54 $outputAsArray = FormatJson
::decode( $output, true );
55 $this->assertSame( 'job-limit', $outputAsArray['reached'] );
56 $this->assertCount( 3, $outputAsArray['jobs'] );
57 foreach ( $outputAsArray['jobs'] as $job ) {
58 $this->assertSame( 'null', $job['type'] );
59 $this->assertSame( 'ok', $job['status'] );