Debian Codegraph @

tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php

raw symbols SCIP
1 <?php
2
3 use MediaWiki\MediaWikiServices;
4 use MediaWiki\Title\Title;
5 use MediaWiki\WikiMap\WikiMap;
6
7 /**
8 * @covers \JobQueueMemory
9 *
10 * @group JobQueue
11 *
12 * @license GPL-2.0-or-later
13 * @author Thiemo Kreuz
14 */
15 class JobQueueMemoryTest extends PHPUnit\Framework\TestCase {
16
17 use MediaWikiCoversValidator;
18
19 /**
20 * @return JobQueueMemory
21 */
22 private function newJobQueue() {
23 $services = MediaWikiServices::getInstance();
24
25 return JobQueue::factory( [
26 'class' => JobQueueMemory::class,
27 'domain' => WikiMap::getCurrentWikiDbDomain()->getId(),
28 'type' => 'null',
29 'idGenerator' => $services->getGlobalIdGenerator(),
30 ] );
31 }
32
33 private function newJobSpecification() {
34 return new JobSpecification(
35 'null',
36 [ 'customParameter' => null ],
37 [],
38 Title::makeTitle( NS_MAIN, 'Custom title' )
39 );
40 }
41
42 public function testGetAllQueuedJobs() {
43 $queue = $this->newJobQueue();
44 $this->assertCount( 0, $queue->getAllQueuedJobs() );
45
46 $queue->push( $this->newJobSpecification() );
47 $this->assertCount( 1, $queue->getAllQueuedJobs() );
48 }
49
50 public function testGetAllAcquiredJobs() {
51 $queue = $this->newJobQueue();
52 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
53
54 $queue->push( $this->newJobSpecification() );
55 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
56
57 $queue->pop();
58 $this->assertCount( 1, $queue->getAllAcquiredJobs() );
59 }
60
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() );
68 }
69
70 }