3 use MediaWiki\JobQueue\JobFactory
;
4 use MediaWiki\Title\Title
;
8 * @covers \MediaWiki\JobQueue\JobFactory
10 class JobFactoryTest
extends MediaWikiIntegrationTestCase
{
13 * @dataProvider provideTestNewJob
15 public function testNewJob( $handler, $expectedClass ) {
17 'testdummy' => $handler
20 $factory = new JobFactory(
21 $this->getServiceContainer()->getObjectFactory(),
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() {
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 );
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,
58 ParsoidCachePrewarmJob
::class
63 public function newNullJob( Title
$title, array $params ) {
64 return new NullJob( $params );