MediaWiki  1.32.5
XhprofTest.php
Go to the documentation of this file.
1 <?php
21 class XhprofTest extends PHPUnit\Framework\TestCase {
22 
23  use MediaWikiCoversValidator;
24 
33  public function testEnable() {
34  $xhprof = new ReflectionClass( Xhprof::class );
35  $enabled = $xhprof->getProperty( 'enabled' );
36  $enabled->setAccessible( true );
37  $enabled->setValue( true );
38  $xhprof->getMethod( 'enable' )->invoke( null );
39  }
40 
47  public function testCallAny( array $functions, array $args, $expectedResult ) {
48  $xhprof = new ReflectionClass( Xhprof::class );
49  $callAny = $xhprof->getMethod( 'callAny' );
50  $callAny->setAccessible( true );
51 
52  $this->assertEquals( $expectedResult,
53  $callAny->invoke( null, $functions, $args ) );
54  }
55 
59  public function provideCallAny() {
60  return [
61  [
62  [ 'wfTestCallAny_func1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
63  [ 3, 4 ],
64  12
65  ],
66  [
67  [ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
68  [ 3, 4 ],
69  7
70  ],
71  [
72  [ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_nosuchfunc2', 'wfTestCallAny_func3' ],
73  [ 3, 4 ],
74  -1
75  ]
76 
77  ];
78  }
79 
87  public function testCallAnyNoneAvailable() {
88  $xhprof = new ReflectionClass( Xhprof::class );
89  $callAny = $xhprof->getMethod( 'callAny' );
90  $callAny->setAccessible( true );
91 
92  $callAny->invoke( $xhprof, [
93  'wfTestCallAny_nosuchfunc1',
94  'wfTestCallAny_nosuchfunc2',
95  'wfTestCallAny_nosuchfunc3'
96  ] );
97  }
98 }
99 
101 function wfTestCallAny_func1( $a, $b ) {
102  return $a * $b;
103 }
104 
106 function wfTestCallAny_func2( $a, $b ) {
107  return $a + $b;
108 }
109 
111 function wfTestCallAny_func3( $a, $b ) {
112  return $a - $b;
113 }
XhprofTest\testCallAnyNoneAvailable
testCallAnyNoneAvailable()
callAny() throws an exception when all functions are unavailable.
Definition: XhprofTest.php:87
XhprofTest
Definition: XhprofTest.php:21
wfTestCallAny_func2
wfTestCallAny_func2( $a, $b)
Test function #2 for XhprofTest::testCallAny.
Definition: XhprofTest.php:106
wfTestCallAny_func1
wfTestCallAny_func1( $a, $b)
Test function #1 for XhprofTest::testCallAny.
Definition: XhprofTest.php:101
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
XhprofTest\testCallAny
testCallAny(array $functions, array $args, $expectedResult)
callAny() calls the first function of the list.
Definition: XhprofTest.php:47
XhprofTest\testEnable
testEnable()
Trying to enable Xhprof when it is already enabled causes an exception to be thrown.
Definition: XhprofTest.php:33
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
$args
if( $line===false) $args
Definition: cdb.php:64
XhprofTest\provideCallAny
provideCallAny()
Data provider for testCallAny().
Definition: XhprofTest.php:59
wfTestCallAny_func3
wfTestCallAny_func3( $a, $b)
Test function #3 for XhprofTest::testCallAny.
Definition: XhprofTest.php:111
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