From f960c2434b7ccd9444e178f033f1f8123da82f7b Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 23 Sep 2014 21:52:39 +0100 Subject: [PATCH] Add tests for Job::toString Change-Id: I00f41808af42a198a1e45a93201dd7bb3e4d9c2c --- includes/jobqueue/Job.php | 6 +- includes/jobqueue/JobQueueGroup.php | 2 +- tests/phpunit/includes/jobqueue/JobTest.php | 67 +++++++++++++++++++++ 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/includes/jobqueue/JobTest.php diff --git a/includes/jobqueue/Job.php b/includes/jobqueue/Job.php index ee3f2c2b60..d89c5d2960 100644 --- a/includes/jobqueue/Job.php +++ b/includes/jobqueue/Job.php @@ -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; diff --git a/includes/jobqueue/JobQueueGroup.php b/includes/jobqueue/JobQueueGroup.php index 98a78c5e39..b0b35e9818 100644 --- a/includes/jobqueue/JobQueueGroup.php +++ b/includes/jobqueue/JobQueueGroup.php @@ -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 index 0000000000..93069d2e8d --- /dev/null +++ b/tests/phpunit/includes/jobqueue/JobTest.php @@ -0,0 +1,67 @@ +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; + } + +} -- 2.20.1