Merge ".mailmap: Correct two contributor names"
[mediawiki.git] / tests / phpunit / includes / jobqueue / JobFactoryTest.php
blob6a62fdfb3d20d44afc276eaea0520dbd7edb0df4
1 <?php
3 use MediaWiki\JobQueue\JobFactory;
4 use MediaWiki\Title\Title;
6 /**
7 * @author Addshore
8 * @covers \MediaWiki\JobQueue\JobFactory
9 */
10 class JobFactoryTest extends MediaWikiIntegrationTestCase {
12 /**
13 * @dataProvider provideTestNewJob
15 public function testNewJob( $handler, $expectedClass ) {
16 $specs = [
17 'testdummy' => $handler
20 $factory = new JobFactory(
21 $this->getServiceContainer()->getObjectFactory(),
22 $specs
25 $job = $factory->newJob( 'testdummy', Title::newMainPage(), [] );
26 $this->assertInstanceOf( $expectedClass, $job );
28 $job2 = $factory->newJob( 'testdummy', [] );
29 $this->assertInstanceOf( $expectedClass, $job2 );
30 $this->assertNotSame( $job, $job2, 'should not reuse instance' );
32 $job3 = $factory->newJob( 'testdummy', [ 'namespace' => NS_MAIN, 'title' => 'JobTestTitle' ] );
33 $this->assertInstanceOf( $expectedClass, $job3 );
34 $this->assertNotSame( $job, $job3, 'should not reuse instance' );
37 public function provideTestNewJob() {
38 return [
39 'class name, no title' => [ 'NullJob', NullJob::class ],
40 'class name with title' => [ DeleteLinksJob::class, DeleteLinksJob::class ],
41 'closure' => [ static function ( Title $title, array $params ) {
42 return new NullJob( $params );
43 }, NullJob::class ],
44 'function' => [ [ $this, 'newNullJob' ], NullJob::class ],
45 'object spec, no title' => [ [ 'class' => 'NullJob' ], NullJob::class ],
46 'object spec with title' => [ [ 'class' => DeleteLinksJob::class ], DeleteLinksJob::class ],
47 'object spec with no title and not subclass of GenericParameterJob' => [
49 'class' => ParsoidCachePrewarmJob::class,
50 'services' => [
51 'ParserOutputAccess',
52 'PageStore',
53 'RevisionLookup',
54 'ParsoidSiteConfig',
56 'needsPage' => false
58 ParsoidCachePrewarmJob::class
63 public function newNullJob( Title $title, array $params ) {
64 return new NullJob( $params );