MediaWiki  1.28.0
JobTest.php
Go to the documentation of this file.
1 <?php
2 
6 class JobTest extends MediaWikiTestCase {
7 
16  public function testToString( $job, $expected ) {
17  $this->assertEquals( $expected, $job->toString() );
18  }
19 
20  public function provideTestToString() {
21  $mockToStringObj = $this->getMock( 'stdClass', [ '__toString' ] );
22  $mockToStringObj->expects( $this->any() )
23  ->method( '__toString' )
24  ->will( $this->returnValue( '{STRING_OBJ_VAL}' ) );
25 
26  $requestId = 'requestId=' . WebRequest::getRequestId();
27 
28  return [
29  [
30  $this->getMockJob( false ),
31  'someCommand ' . $requestId
32  ],
33  [
34  $this->getMockJob( [ 'key' => 'val' ] ),
35  'someCommand key=val ' . $requestId
36  ],
37  [
38  $this->getMockJob( [ 'key' => [ 'inkey' => 'inval' ] ] ),
39  'someCommand key={"inkey":"inval"} ' . $requestId
40  ],
41  [
42  $this->getMockJob( [ 'val1' ] ),
43  'someCommand 0=val1 ' . $requestId
44  ],
45  [
46  $this->getMockJob( [ 'val1', 'val2' ] ),
47  'someCommand 0=val1 1=val2 ' . $requestId
48  ],
49  [
50  $this->getMockJob( [ new stdClass() ] ),
51  'someCommand 0=object(stdClass) ' . $requestId
52  ],
53  [
54  $this->getMockJob( [ $mockToStringObj ] ),
55  'someCommand 0={STRING_OBJ_VAL} ' . $requestId
56  ],
57  [
58  $this->getMockJob( [
59  "pages" => [
60  "932737" => [
61  0,
62  "Robert_James_Waller"
63  ]
64  ],
65  "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7",
66  "rootJobTimestamp" => "20160309110158",
67  "masterPos" => [
68  "file" => "db1023-bin.001288",
69  "pos" => "308257743",
70  "asOfTime" => 1457521464.3814
71  ],
72  "triggeredRecursive" => true
73  ] ),
74  'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' .
75  'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' .
76  'rootJobTimestamp=20160309110158 masterPos=' .
77  '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' .
78  'triggeredRecursive=1 ' .
79  $requestId
80  ],
81  ];
82  }
83 
84  public function getMockJob( $params ) {
85  $mock = $this->getMockForAbstractClass(
86  'Job',
87  [ 'someCommand', new Title(), $params ],
88  'SomeJob'
89  );
90  return $mock;
91  }
92 
93 }
static getRequestId()
Get the unique request ID.
Definition: WebRequest.php:272
provideTestToString()
Definition: JobTest.php:20
$params
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
testToString($job, $expected)
provideTestToString
Definition: JobTest.php:16
if(count($args)< 1) $job
getMockJob($params)
Definition: JobTest.php:84