aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/jobqueue/JobTest.php
diff options
context:
space:
mode:
authorLucas Werkmeister <lucas.werkmeister@wikimedia.de>2017-05-04 18:00:28 +0200
committerLucas Werkmeister <lucas.werkmeister@wikimedia.de>2017-05-09 19:26:13 +0200
commita57252a1f521344e53e8776c34f925f522f512f3 (patch)
tree55e6faf7e1c9aa741417ec7afbd1f03dea0e7e3c /tests/phpunit/includes/jobqueue/JobTest.php
parenta559a5e406f40016fd9ec466598668d8adfc398c (diff)
downloadmediawikicore-a57252a1f521344e53e8776c34f925f522f512f3.tar.gz
mediawikicore-a57252a1f521344e53e8776c34f925f522f512f3.zip
Allow callback functions for creating jobs
$wgJobClasses can now specify a factory function for creating a job, instead of a class to be instantiated directly. This makes it possible to inject services in a job constructor, and register a factory function that calls the constructor with default services. This follows Ieb85493a7765 and Ia2107dc5af78, which introduced factory functions for API modules and special pages. Change-Id: I0461e59da2a8fa6681e3b1fcdfc38bfed7f3ac32
Diffstat (limited to 'tests/phpunit/includes/jobqueue/JobTest.php')
-rw-r--r--tests/phpunit/includes/jobqueue/JobTest.php37
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 );
+ }
+
}