MediaWiki  1.30.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->getMockBuilder( 'stdClass' )
22  ->setMethods( [ '__toString' ] )->getMock();
23  $mockToStringObj->expects( $this->any() )
24  ->method( '__toString' )
25  ->will( $this->returnValue( '{STRING_OBJ_VAL}' ) );
26 
27  $requestId = 'requestId=' . WebRequest::getRequestId();
28 
29  return [
30  [
31  $this->getMockJob( false ),
32  'someCommand ' . $requestId
33  ],
34  [
35  $this->getMockJob( [ 'key' => 'val' ] ),
36  'someCommand key=val ' . $requestId
37  ],
38  [
39  $this->getMockJob( [ 'key' => [ 'inkey' => 'inval' ] ] ),
40  'someCommand key={"inkey":"inval"} ' . $requestId
41  ],
42  [
43  $this->getMockJob( [ 'val1' ] ),
44  'someCommand 0=val1 ' . $requestId
45  ],
46  [
47  $this->getMockJob( [ 'val1', 'val2' ] ),
48  'someCommand 0=val1 1=val2 ' . $requestId
49  ],
50  [
51  $this->getMockJob( [ new stdClass() ] ),
52  'someCommand 0=object(stdClass) ' . $requestId
53  ],
54  [
55  $this->getMockJob( [ $mockToStringObj ] ),
56  'someCommand 0={STRING_OBJ_VAL} ' . $requestId
57  ],
58  [
59  $this->getMockJob( [
60  "pages" => [
61  "932737" => [
62  0,
63  "Robert_James_Waller"
64  ]
65  ],
66  "rootJobSignature" => "45868e99bba89064e4483743ebb9b682ef95c1a7",
67  "rootJobTimestamp" => "20160309110158",
68  "masterPos" => [
69  "file" => "db1023-bin.001288",
70  "pos" => "308257743",
71  "asOfTime" => 1457521464.3814
72  ],
73  "triggeredRecursive" => true
74  ] ),
75  'someCommand pages={"932737":[0,"Robert_James_Waller"]} ' .
76  'rootJobSignature=45868e99bba89064e4483743ebb9b682ef95c1a7 ' .
77  'rootJobTimestamp=20160309110158 masterPos=' .
78  '{"file":"db1023-bin.001288","pos":"308257743","asOfTime":1457521464.3814} ' .
79  'triggeredRecursive=1 ' .
80  $requestId
81  ],
82  ];
83  }
84 
85  public function getMockJob( $params ) {
86  $mock = $this->getMockForAbstractClass(
87  'Job',
88  [ 'someCommand', new Title(), $params ],
89  'SomeJob'
90  );
91  return $mock;
92  }
93 
101  public function testJobFactory( $handler ) {
102  $this->mergeMWGlobalArrayValue( 'wgJobClasses', [ 'testdummy' => $handler ] );
103 
104  $job = Job::factory( 'testdummy', Title::newMainPage(), [] );
105  $this->assertInstanceOf( NullJob::class, $job );
106 
107  $job2 = Job::factory( 'testdummy', Title::newMainPage(), [] );
108  $this->assertInstanceOf( NullJob::class, $job2 );
109  $this->assertNotSame( $job, $job2, 'should not reuse instance' );
110  }
111 
112  public function provideTestJobFactory() {
113  return [
114  'class name' => [ 'NullJob' ],
115  'closure' => [ function ( Title $title, array $params ) {
116  return new NullJob( $title, $params );
117  } ],
118  'function' => [ [ $this, 'newNullJob' ] ],
119  'static function' => [ self::class . '::staticNullJob' ]
120  ];
121  }
122 
123  public function newNullJob( Title $title, array $params ) {
124  return new NullJob( $title, $params );
125  }
126 
127  public static function staticNullJob( Title $title, array $params ) {
128  return new NullJob( $title, $params );
129  }
130 
131 }
JobTest\getMockJob
getMockJob( $params)
Definition: JobTest.php:85
JobTest\testToString
testToString( $job, $expected)
provideTestToString
Definition: JobTest.php:16
Title\newMainPage
static newMainPage()
Create a new Title for the Main Page.
Definition: Title.php:581
JobTest\provideTestJobFactory
provideTestJobFactory()
Definition: JobTest.php:112
$params
$params
Definition: styleTest.css.php:40
NullJob
Degenerate job that does nothing, but can optionally replace itself in the queue and/or sleep for a b...
Definition: NullJob.php:47
JobTest\provideTestToString
provideTestToString()
Definition: JobTest.php:20
php
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
Job\factory
static factory( $command, Title $title, $params=[])
Create the appropriate object to handle a specific job.
Definition: Job.php:68
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:932
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
JobTest\testJobFactory
testJobFactory( $handler)
provideTestJobFactory
Definition: JobTest.php:101
$handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:781
Title
Represents a title within MediaWiki.
Definition: Title.php:39
JobTest
Definition: JobTest.php:6
$job
if(count( $args)< 1) $job
Definition: recompressTracked.php:47
WebRequest\getRequestId
static getRequestId()
Get the unique request ID.
Definition: WebRequest.php:272
JobTest\newNullJob
newNullJob(Title $title, array $params)
Definition: JobTest.php:123
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
JobTest\staticNullJob
static staticNullJob(Title $title, array $params)
Definition: JobTest.php:127
array
the array() calling protocol came about after MediaWiki 1.4rc1.