1<?php
2/*
3 * This file is part of php-token-stream.
4 *
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11use PHPUnit\Framework\TestCase;
12
13class PHP_Token_ClosureTest extends TestCase
14{
15    /**
16     * @var PHP_Token_FUNCTION[]
17     */
18    private $functions;
19
20    protected function setUp()
21    {
22        $ts = new PHP_Token_Stream(TEST_FILES_PATH . 'closure.php');
23
24        foreach ($ts as $token) {
25            if ($token instanceof PHP_Token_FUNCTION) {
26                $this->functions[] = $token;
27            }
28        }
29    }
30
31    /**
32     * @covers PHP_Token_FUNCTION::getArguments
33     */
34    public function testGetArguments()
35    {
36        $this->assertEquals(['$foo' => null, '$bar' => null], $this->functions[0]->getArguments());
37        $this->assertEquals(['$foo' => 'Foo', '$bar' => null], $this->functions[1]->getArguments());
38        $this->assertEquals(['$foo' => null, '$bar' => null, '$baz' => null], $this->functions[2]->getArguments());
39        $this->assertEquals(['$foo' => 'Foo', '$bar' => null, '$baz' => null], $this->functions[3]->getArguments());
40        $this->assertEquals([], $this->functions[4]->getArguments());
41        $this->assertEquals([], $this->functions[5]->getArguments());
42    }
43
44    /**
45     * @covers PHP_Token_FUNCTION::getName
46     */
47    public function testGetName()
48    {
49        $this->assertEquals('anonymousFunction:2#5', $this->functions[0]->getName());
50        $this->assertEquals('anonymousFunction:3#27', $this->functions[1]->getName());
51        $this->assertEquals('anonymousFunction:4#51', $this->functions[2]->getName());
52        $this->assertEquals('anonymousFunction:5#71', $this->functions[3]->getName());
53        $this->assertEquals('anonymousFunction:6#93', $this->functions[4]->getName());
54        $this->assertEquals('anonymousFunction:7#106', $this->functions[5]->getName());
55    }
56
57    /**
58     * @covers PHP_Token::getLine
59     */
60    public function testGetLine()
61    {
62        $this->assertEquals(2, $this->functions[0]->getLine());
63        $this->assertEquals(3, $this->functions[1]->getLine());
64        $this->assertEquals(4, $this->functions[2]->getLine());
65        $this->assertEquals(5, $this->functions[3]->getLine());
66    }
67
68    /**
69     * @covers PHP_TokenWithScope::getEndLine
70     */
71    public function testGetEndLine()
72    {
73        $this->assertEquals(2, $this->functions[0]->getLine());
74        $this->assertEquals(3, $this->functions[1]->getLine());
75        $this->assertEquals(4, $this->functions[2]->getLine());
76        $this->assertEquals(5, $this->functions[3]->getLine());
77    }
78}
79