From 1910da184e80c2e1ce496fc5a41bdae53e7ae14c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thiemo=20M=C3=A4ttig?= Date: Thu, 14 Jan 2016 12:59:23 +0100 Subject: [PATCH] Do not return null reference in JobQueueMemory See Ia5b7a96 and the unrelated error raised there. https://integration.wikimedia.org/ci/job/mwext-testextension-zend/19682/consoleFull By writing this simple test I not only found one but two issues. Bug: T123539 Change-Id: I17ed5b69992aa98ab2384b7a6aafc96b0fcba1ce --- includes/jobqueue/JobQueueMemory.php | 4 +-- .../includes/jobqueue/JobQueueMemoryTest.php | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php diff --git a/includes/jobqueue/JobQueueMemory.php b/includes/jobqueue/JobQueueMemory.php index c5d7257468..d9b30c729e 100644 --- a/includes/jobqueue/JobQueueMemory.php +++ b/includes/jobqueue/JobQueueMemory.php @@ -57,7 +57,7 @@ class JobQueueMemory extends JobQueue { } protected function optimalOrder() { - return array( 'fifo' ); + return 'fifo'; } protected function doIsEmpty() { @@ -160,7 +160,7 @@ class JobQueueMemory extends JobQueue { if ( $init !== null ) { self::$data[$this->type][$this->wiki][$field] = $init; } else { - return null; + return $init; } } diff --git a/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php b/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php new file mode 100644 index 0000000000..a9f7e0edc5 --- /dev/null +++ b/tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php @@ -0,0 +1,30 @@ + null, + 'type' => null, + ) ); + $actual = $instance->getAllQueuedJobs(); + $this->assertEquals( new ArrayIterator(), $actual ); + } + +} + +class JobQueueMemoryDouble extends JobQueueMemory { + + public static function newInstance( array $params ) { + return new self( $params ); + } + +} -- 2.20.1