summaryrefslogtreecommitdiff
path: root/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php
blob: bb2b33fe5b40af0c7bb026ca861bba50efe52f1c (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
41
42
43
44
45
46
<?php

/**
 * @group GlobalFunctions
 * @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 )
			);
		}
	}
}