File tree Expand file tree Collapse file tree 3 files changed +54
-0
lines changed 
tests/PHPStan/Ast/NodeVisitor Expand file tree Collapse file tree 3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -11,4 +11,6 @@ final class Attribute
1111	public  const  START_INDEX  = 'startIndex ' ;
1212	public  const  END_INDEX  = 'endIndex ' ;
1313
14+ 	public  const  ORIGINAL_NODE  = 'originalNode ' ;
15+ 
1416}
Original file line number Diff line number Diff line change 1+ <?php  declare (strict_types = 1 );
2+ 
3+ namespace  PHPStan \PhpDocParser \Ast \NodeVisitor ;
4+ 
5+ use  PHPStan \PhpDocParser \Ast \AbstractNodeVisitor ;
6+ use  PHPStan \PhpDocParser \Ast \Attribute ;
7+ use  PHPStan \PhpDocParser \Ast \Node ;
8+ 
9+ final  class  CloningVisitor extends  AbstractNodeVisitor
10+ {
11+ 
12+ 	public  function  enterNode (Node $ originalNode
13+ 	{
14+ 		$ nodeclone  $ originalNode
15+ 		$ nodesetAttribute (Attribute::ORIGINAL_NODE , $ originalNode
16+ 
17+ 		return  $ node
18+ 	}
19+ 
20+ }
Original file line number Diff line number Diff line change 1+ <?php  declare (strict_types = 1 );
2+ 
3+ namespace  PHPStan \PhpDocParser \Ast \NodeVisitor ;
4+ 
5+ use  PHPStan \PhpDocParser \Ast \Attribute ;
6+ use  PHPStan \PhpDocParser \Ast \NodeTraverser ;
7+ use  PHPStan \PhpDocParser \Ast \Type \IdentifierTypeNode ;
8+ use  PHPStan \PhpDocParser \Ast \Type \NullableTypeNode ;
9+ use  PHPUnit \Framework \TestCase ;
10+ 
11+ class  CloningVisitorTest extends  TestCase
12+ {
13+ 
14+ 	public  function  testVisitor (): void 
15+ 	{
16+ 		$ visitornew  CloningVisitor ();
17+ 		$ traversernew  NodeTraverser ([$ visitor
18+ 		$ identifiernew  IdentifierTypeNode ('Foo ' );
19+ 		$ nodenew  NullableTypeNode ($ identifier
20+ 
21+ 		$ newNodes$ traversertraverse ([$ node
22+ 		$ this assertCount (1 , $ newNodes
23+ 		$ this assertInstanceOf (NullableTypeNode::class, $ newNodes0 ]);
24+ 		$ this assertNotSame ($ node$ newNodes0 ]);
25+ 		$ this assertSame ($ node$ newNodes0 ]->getAttribute (Attribute::ORIGINAL_NODE ));
26+ 
27+ 		$ this assertInstanceOf (IdentifierTypeNode::class, $ newNodes0 ]->type );
28+ 		$ this assertNotSame ($ identifier$ newNodes0 ]->type );
29+ 		$ this assertSame ($ identifier$ newNodes0 ]->type ->getAttribute (Attribute::ORIGINAL_NODE ));
30+ 	}
31+ 
32+ }
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments