Clean up spacing of doc comments
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / XhprofTest.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 class XhprofTest extends PHPUnit\Framework\TestCase {
22
23 use MediaWikiCoversValidator;
24
25 /**
26 * Trying to enable Xhprof when it is already enabled causes an exception
27 * to be thrown.
28 *
29 * @expectedException Exception
30 * @expectedExceptionMessage already enabled
31 * @covers Xhprof::enable
32 */
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
41 /**
42 * callAny() calls the first function of the list.
43 *
44 * @covers Xhprof::callAny
45 * @dataProvider provideCallAny
46 */
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
56 /**
57 * Data provider for testCallAny().
58 */
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
80 /**
81 * callAny() throws an exception when all functions are unavailable.
82 *
83 * @expectedException Exception
84 * @expectedExceptionMessage Neither xhprof nor tideways are installed
85 * @covers Xhprof::callAny
86 */
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
100 /** Test function #1 for XhprofTest::testCallAny */
101 function wfTestCallAny_func1( $a, $b ) {
102 return $a * $b;
103 }
104
105 /** Test function #2 for XhprofTest::testCallAny */
106 function wfTestCallAny_func2( $a, $b ) {
107 return $a + $b;
108 }
109
110 /** Test function #3 for XhprofTest::testCallAny */
111 function wfTestCallAny_func3( $a, $b ) {
112 return $a - $b;
113 }