File: JobFactoryTest.php

package info (click to toggle)
mediawiki 1%3A1.43.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 420,592 kB
  • sloc: php: 1,064,309; javascript: 664,315; sql: 9,737; python: 5,743; xml: 3,489; sh: 1,131; makefile: 64
file content (66 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php

use MediaWiki\JobQueue\JobFactory;
use MediaWiki\Title\Title;

/**
 * @author Addshore
 * @covers \MediaWiki\JobQueue\JobFactory
 */
class JobFactoryTest extends MediaWikiIntegrationTestCase {

	/**
	 * @dataProvider provideTestNewJob
	 */
	public function testNewJob( $handler, $expectedClass ) {
		$specs = [
			'testdummy' => $handler
		];

		$factory = new JobFactory(
			$this->getServiceContainer()->getObjectFactory(),
			$specs
		);

		$job = $factory->newJob( 'testdummy', Title::newMainPage(), [] );
		$this->assertInstanceOf( $expectedClass, $job );

		$job2 = $factory->newJob( 'testdummy', [] );
		$this->assertInstanceOf( $expectedClass, $job2 );
		$this->assertNotSame( $job, $job2, 'should not reuse instance' );

		$job3 = $factory->newJob( 'testdummy', [ 'namespace' => NS_MAIN, 'title' => 'JobTestTitle' ] );
		$this->assertInstanceOf( $expectedClass, $job3 );
		$this->assertNotSame( $job, $job3, 'should not reuse instance' );
	}

	public function provideTestNewJob() {
		return [
			'class name, no title' => [ 'NullJob', NullJob::class ],
			'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
			'closure' => [ static function ( Title $title, array $params ) {
				return new NullJob( $params );
			}, NullJob::class ],
			'function' => [ [ $this, 'newNullJob' ], NullJob::class ],
			'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
			'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
			'object spec with no title and not subclass of GenericParameterJob' => [
				[
					'class' => ParsoidCachePrewarmJob::class,
					'services' => [
						'ParserOutputAccess',
						'PageStore',
						'RevisionLookup',
						'ParsoidSiteConfig',
					],
					'needsPage' => false
				],
				ParsoidCachePrewarmJob::class
			]
		];
	}

	public function newNullJob( Title $title, array $params ) {
		return new NullJob( $params );
	}
}