summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php
blob: 6229624586df186b84813ab89317047504ed5f80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

/**
 * @covers ::wfGetCaller
 */
class WfGetCallerTest extends MediaWikiTestCase {

	public function testZero() {
		$this->assertEquals( __METHOD__, wfGetCaller( 1 ) );
	}

	function callerOne() {
		return wfGetCaller();
	}

	public function testOne() {
		$this->assertEquals( 'WfGetCallerTest::testOne', self::callerOne() );
	}

	function intermediateFunction( $level = 2, $n = 0 ) {
		if ( $n > 0 ) {
			return self::intermediateFunction( $level, $n - 1 );
		}

		return wfGetCaller( $level );
	}

	public function testTwo() {
		$this->assertEquals( 'WfGetCallerTest::testTwo', self::intermediateFunction() );
	}

	public function testN() {
		$this->assertEquals( 'WfGetCallerTest::testN', self::intermediateFunction( 2, 0 ) );
		$this->assertEquals( 'WfGetCallerTest::intermediateFunction', self::intermediateFunction( 1, 0 ) );

		for ( $i = 0; $i < 10; $i++ ) {
			$this->assertEquals( 'WfGetCallerTest::intermediateFunction', self::intermediateFunction( $i + 1, $i ) );
		}
	}
}