Do not return null reference in JobQueueMemory
authorThiemo Mättig <thiemo.maettig@wikimedia.de>
Thu, 14 Jan 2016 11:59:23 +0000 (12:59 +0100)
committerThiemo Mättig <thiemo.maettig@wikimedia.de>
Thu, 14 Jan 2016 18:19:55 +0000 (19:19 +0100)
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
tests/phpunit/includes/jobqueue/JobQueueMemoryTest.php [new file with mode: 0644]

index c5d7257..d9b30c7 100644 (file)
@@ -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 (file)
index 0000000..a9f7e0e
--- /dev/null
@@ -0,0 +1,30 @@
+<?php
+
+/**
+ * @covers JobQueueMemory
+ *
+ * @group JobQueue
+ *
+ * @licence GNU GPL v2+
+ * @author Thiemo Mättig
+ */
+class JobQueueMemoryTest extends PHPUnit_Framework_TestCase {
+
+       public function testGetAllQueuedJobs() {
+               $instance = JobQueueMemoryDouble::newInstance( array(
+                       'wiki' => 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 );
+       }
+
+}