diff options
Diffstat (limited to 'tests/phpunit/includes/jobqueue/JobTest.php')
-rw-r--r-- | tests/phpunit/includes/jobqueue/JobTest.php | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php index 1deb7aa35d86..00c47c8ae8f6 100644 --- a/tests/phpunit/includes/jobqueue/JobTest.php +++ b/tests/phpunit/includes/jobqueue/JobTest.php @@ -91,4 +91,41 @@ class JobTest extends MediaWikiTestCase { return $mock; } + /** + * @dataProvider provideTestJobFactory + * + * @param mixed $handler + * + * @covers Job::factory + */ + public function testJobFactory( $handler ) { + $this->mergeMWGlobalArrayValue( 'wgJobClasses', [ 'testdummy' => $handler ] ); + + $job = Job::factory( 'testdummy', Title::newMainPage(), [] ); + $this->assertInstanceOf( NullJob::class, $job ); + + $job2 = Job::factory( 'testdummy', Title::newMainPage(), [] ); + $this->assertInstanceOf( NullJob::class, $job2 ); + $this->assertNotSame( $job, $job2, 'should not reuse instance' ); + } + + public function provideTestJobFactory() { + return [ + 'class name' => [ 'NullJob' ], + 'closure' => [ function( Title $title, array $params ) { + return new NullJob( $title, $params ); + } ], + 'function' => [ [ $this, 'newNullJob' ] ], + 'static function' => [ self::class . '::staticNullJob' ] + ]; + } + + public function newNullJob( Title $title, array $params ) { + return new NullJob( $title, $params ); + } + + public static function staticNullJob( Title $title, array $params ) { + return new NullJob( $title, $params ); + } + } |