Subversion Repository Public Repository

Nextrek

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
47
48
49
50
51
52
53
54
55
56
57
<?php

namespace Jeremeamia\SuperClosure\Test\Visitor;

use Jeremeamia\SuperClosure\Visitor\ClosureFinderVisitor;

/**
 * @covers Jeremeamia\SuperClosure\Visitor\ClosureFinderVisitor
 */
class ClosureFinderVisitorTest extends \PHPUnit_Framework_TestCase
{
    public function testClosureNodeIsDiscoveredByVisitor()
    {
        $closure = function () {}; // Take the line number here and set it as the "startLine"
        $reflectedClosure = new \ReflectionFunction($closure);
        $closureFinder = new ClosureFinderVisitor($reflectedClosure);
        $closureNode = new \PHPParser_Node_Expr_Closure(array(), array('startLine' => 14));
        $closureFinder->enterNode($closureNode);

        $this->assertSame($closureNode, $closureFinder->getClosureNode());
    }

    public function testClosureNodeIsAmbiguousIfMultipleClosuresOnLine()
    {
        $this->setExpectedException('RuntimeException');

        $closure = function () {}; function () {}; // Take the line number here and set it as the "startLine"
        $closureFinder = new ClosureFinderVisitor(new \ReflectionFunction($closure));
        $closureFinder->enterNode(new \PHPParser_Node_Expr_Closure(array(), array('startLine' => 27)));
        $closureFinder->enterNode(new \PHPParser_Node_Expr_Closure(array(), array('startLine' => 27)));
    }

    public function testCalculatesClosureLocation()
    {
        $closure = function () {}; // Take the line number here and set it as the "startLine"
        $closureFinder = new ClosureFinderVisitor(new \ReflectionFunction($closure));

        $closureFinder->beforeTraverse(array());

        $node = new \PHPParser_Node_Stmt_Namespace(new \PHPParser_Node_Name(array('Foo', 'Bar')));
        $closureFinder->enterNode($node);
        $closureFinder->leaveNode($node);

        $node = new \PHPParser_Node_Stmt_Trait('Fizz');
        $closureFinder->enterNode($node);
        $closureFinder->leaveNode($node);

        $node = new \PHPParser_Node_Stmt_Class('Buzz');
        $closureFinder->enterNode($node);
        $closureFinder->leaveNode($node);

        $closureFinder->afterTraverse(array());

        $setProperties = array_filter(get_object_vars($closureFinder->getLocation()));
        $this->assertEquals(array('directory', 'file', 'function', 'line'), array_keys($setProperties));
    }
}

Commits for Nextrek/Aiba_backup/vendor/jeremeamia/SuperClosure/tests/Jeremeamia/SuperClosure/Test/Visitor/ClosureFinderVisitorTest.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000