aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/GlobalFunctions/WfGetCallerTest.php
blob: 8a00da124967ffb5974690038328cc7749655b85 (plain) (blame)
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 MediaWikiUnitTestCase {
	public function testZero() {
		$this->assertEquals( 'WfGetCallerTest->testZero', wfGetCaller( 1 ) );
	}

	public function callerOne() {
		return wfGetCaller();
	}

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

	public static 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 )
			);
		}
	}
}