Merge "maintenance: Document secondary purpose of --server"
[lhc/web/wiklou.git] / tests / phpunit / includes / jobqueue / JobQueueMemoryTest.php
1 <?php
2
3 /**
4 * @covers JobQueueMemory
5 *
6 * @group JobQueue
7 *
8 * @license GNU GPL v2+
9 * @author Thiemo Kreuz
10 */
11 class JobQueueMemoryTest extends PHPUnit\Framework\TestCase {
12
13 use MediaWikiCoversValidator;
14
15 /**
16 * @return JobQueueMemory
17 */
18 private function newJobQueue() {
19 return JobQueue::factory( [
20 'class' => JobQueueMemory::class,
21 'wiki' => wfWikiID(),
22 'type' => 'null',
23 ] );
24 }
25
26 private function newJobSpecification() {
27 return new JobSpecification(
28 'null',
29 [ 'customParameter' => null ],
30 [],
31 Title::newFromText( 'Custom title' )
32 );
33 }
34
35 public function testGetAllQueuedJobs() {
36 $queue = $this->newJobQueue();
37 $this->assertCount( 0, $queue->getAllQueuedJobs() );
38
39 $queue->push( $this->newJobSpecification() );
40 $this->assertCount( 1, $queue->getAllQueuedJobs() );
41 }
42
43 public function testGetAllAcquiredJobs() {
44 $queue = $this->newJobQueue();
45 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
46
47 $queue->push( $this->newJobSpecification() );
48 $this->assertCount( 0, $queue->getAllAcquiredJobs() );
49
50 $queue->pop();
51 $this->assertCount( 1, $queue->getAllAcquiredJobs() );
52 }
53
54 public function testJobFromSpecInternal() {
55 $queue = $this->newJobQueue();
56 $job = $queue->jobFromSpecInternal( $this->newJobSpecification() );
57 $this->assertInstanceOf( Job::class, $job );
58 $this->assertSame( 'null', $job->getType() );
59 $this->assertArrayHasKey( 'customParameter', $job->getParams() );
60 $this->assertSame( 'Custom title', $job->getTitle()->getText() );
61 }
62
63 }