Add tests for Job::toString
authoraddshore <addshorewiki@gmail.com>
Tue, 23 Sep 2014 20:52:39 +0000 (21:52 +0100)
committeraddshore <addshorewiki@gmail.com>
Tue, 23 Sep 2014 20:57:31 +0000 (21:57 +0100)
Change-Id: I00f41808af42a198a1e45a93201dd7bb3e4d9c2c

includes/jobqueue/Job.php
includes/jobqueue/JobQueueGroup.php
tests/phpunit/includes/jobqueue/JobTest.php [new file with mode: 0644]

index ee3f2c2..d89c5d2 100644 (file)
@@ -87,7 +87,7 @@ abstract class Job implements IJobSpecification {
         * This may add duplicate at insert time, but they will be
         * removed later on, when the first one is popped.
         *
-        * @param array $jobs Array of Job objects
+        * @param Job[] $jobs Array of Job objects
         * @return bool
         * @deprecated since 1.21
         */
@@ -103,7 +103,7 @@ abstract class Job implements IJobSpecification {
         * be rolled-back as part of a larger transaction. However,
         * large batches of jobs can cause slave lag.
         *
-        * @param array $jobs Array of Job objects
+        * @param Job[] $jobs Array of Job objects
         * @return bool
         * @deprecated since 1.21
         */
@@ -143,7 +143,7 @@ abstract class Job implements IJobSpecification {
        /**
         * @param string $command
         * @param Title $title
-        * @param array|bool $params
+        * @param array|bool $params Can not be === true
         */
        public function __construct( $command, $title, $params = false ) {
                $this->command = $command;
index 98a78c5..b0b35e9 100644 (file)
@@ -104,7 +104,7 @@ class JobQueueGroup {
         * This inserts the jobs into the queue specified by $wgJobTypeConf
         * and updates the aggregate job queue information cache as needed.
         *
-        * @param Job|array $jobs A single Job or a list of Jobs
+        * @param Job|Job[] $jobs A single Job or a list of Jobs
         * @throws MWException
         * @return void
         */
diff --git a/tests/phpunit/includes/jobqueue/JobTest.php b/tests/phpunit/includes/jobqueue/JobTest.php
new file mode 100644 (file)
index 0000000..93069d2
--- /dev/null
@@ -0,0 +1,67 @@
+<?php
+
+/**
+ * @author Adam Shorland
+ */
+class JobTest extends MediaWikiTestCase {
+
+       /**
+        * @dataProvider provideTestToString
+        *
+        * @param Job $job
+        * @param string $expected
+        *
+        * @covers Job::toString
+        */
+       public function testToString( $job, $expected ) {
+               $this->assertEquals( $expected, $job->toString() );
+       }
+
+       public function provideTestToString() {
+               $mockToStringObj = $this->getMock( 'stdClass', array( '__toString' ) );
+               $mockToStringObj->expects( $this->any() )
+                       ->method( '__toString' )
+                       ->will( $this->returnValue( '{STRING_OBJ_VAL}' ) );
+
+               return array(
+                       array(
+                               $this->getMockJob( false ),
+                               'someCommand '
+                       ),
+                       array(
+                               $this->getMockJob( array( 'key' => 'val' ) ),
+                               'someCommand  key=val'
+                       ),
+                       array(
+                               $this->getMockJob( array( 'key' => array( 'inkey' => 'inval' ) ) ),
+                               'someCommand  key={"inkey":"inval"}'
+                       ),
+                       array(
+                               $this->getMockJob( array( 'val1' ) ),
+                               'someCommand  0=val1'
+                       ),
+                       array(
+                               $this->getMockJob( array( 'val1', 'val2' ) ),
+                               'someCommand  0=val1 1=val2'
+                       ),
+                       array(
+                               $this->getMockJob( array( new stdClass() ) ),
+                               'someCommand  0=object(stdClass)'
+                       ),
+                       array(
+                               $this->getMockJob( array( $mockToStringObj ) ),
+                               'someCommand  0={STRING_OBJ_VAL}'
+                       ),
+               );
+       }
+
+       public function getMockJob( $params ) {
+               $mock = $this->getMockForAbstractClass(
+                       'Job',
+                       array( 'someCommand', new Title(), $params ),
+                       'SomeJob'
+               );
+               return $mock;
+       }
+
+}