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.
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.
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
21 class XhprofTest
extends PHPUnit\Framework\TestCase
{
23 use MediaWikiCoversValidator
;
26 * Trying to enable Xhprof when it is already enabled causes an exception
29 * @expectedException Exception
30 * @expectedExceptionMessage already enabled
31 * @covers Xhprof::enable
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 );
42 * callAny() calls the first function of the list.
44 * @covers Xhprof::callAny
45 * @dataProvider provideCallAny
47 public function testCallAny( array $functions, array $args, $expectedResult ) {
48 $xhprof = new ReflectionClass( Xhprof
::class );
49 $callAny = $xhprof->getMethod( 'callAny' );
50 $callAny->setAccessible( true );
52 $this->assertEquals( $expectedResult,
53 $callAny->invoke( null, $functions, $args ) );
57 * Data provider for testCallAny().
59 public function provideCallAny() {
62 [ 'wfTestCallAny_func1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
67 [ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_func2', 'wfTestCallAny_func3' ],
72 [ 'wfTestCallAny_nosuchfunc1', 'wfTestCallAny_nosuchfunc2', 'wfTestCallAny_func3' ],
81 * callAny() throws an exception when all functions are unavailable.
83 * @expectedException Exception
84 * @expectedExceptionMessage Neither xhprof nor tideways are installed
85 * @covers Xhprof::callAny
87 public function testCallAnyNoneAvailable() {
88 $xhprof = new ReflectionClass( Xhprof
::class );
89 $callAny = $xhprof->getMethod( 'callAny' );
90 $callAny->setAccessible( true );
92 $callAny->invoke( $xhprof, [
93 'wfTestCallAny_nosuchfunc1',
94 'wfTestCallAny_nosuchfunc2',
95 'wfTestCallAny_nosuchfunc3'
100 /** Test function #1 for XhprofTest::testCallAny */
101 function wfTestCallAny_func1( $a, $b ) {
105 /** Test function #2 for XhprofTest::testCallAny */
106 function wfTestCallAny_func2( $a, $b ) {
110 /** Test function #3 for XhprofTest::testCallAny */
111 function wfTestCallAny_func3( $a, $b ) {