3 use MediaWiki\MediaWikiServices
;
4 use MediaWiki\Title\Title
;
5 use MediaWiki\WikiMap\WikiMap
;
8 * @covers \JobQueueMemory
12 * @license GPL-2.0-or-later
13 * @author Thiemo Kreuz
15 class JobQueueMemoryTest
extends PHPUnit\Framework\TestCase
{
17 use MediaWikiCoversValidator
;
20 * @return JobQueueMemory
22 private function newJobQueue() {
23 $services = MediaWikiServices
::getInstance();
25 return JobQueue
::factory( [
26 'class' => JobQueueMemory
::class,
27 'domain' => WikiMap
::getCurrentWikiDbDomain()->getId(),
29 'idGenerator' => $services->getGlobalIdGenerator(),
33 private function newJobSpecification() {
34 return new JobSpecification(
36 [ 'customParameter' => null ],
38 Title
::makeTitle( NS_MAIN
, 'Custom title' )
42 public function testGetAllQueuedJobs() {
43 $queue = $this->newJobQueue();
44 $this->assertCount( 0, $queue->getAllQueuedJobs() );
46 $queue->push( $this->newJobSpecification() );
47 $this->assertCount( 1, $queue->getAllQueuedJobs() );
50 public function testGetAllAcquiredJobs() {
51 $queue = $this->newJobQueue();
52 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
54 $queue->push( $this->newJobSpecification() );
55 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
58 $this->assertCount( 1, $queue->getAllAcquiredJobs() );
61 public function testJobFromSpecInternal() {
62 $queue = $this->newJobQueue();
63 $job = $queue->jobFromSpecInternal( $this->newJobSpecification() );
64 $this->assertInstanceOf( Job
::class, $job );
65 $this->assertSame( 'null', $job->getType() );
66 $this->assertArrayHasKey( 'customParameter', $job->getParams() );
67 $this->assertSame( 'Custom title', $job->getTitle()->getText() );