File: CloningVisitorTest.php

package info (click to toggle)
php-phpstan-phpdoc-parser 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,476 kB
  • sloc: php: 21,156; makefile: 50; xml: 42; sh: 17
file content (32 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download | duplicates (2)
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
<?php declare(strict_types = 1);

namespace PHPStan\PhpDocParser\Ast\NodeVisitor;

use PHPStan\PhpDocParser\Ast\Attribute;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode;
use PHPUnit\Framework\TestCase;

class CloningVisitorTest extends TestCase
{

	public function testVisitor(): void
	{
		$visitor = new CloningVisitor();
		$traverser = new NodeTraverser([$visitor]);
		$identifier = new IdentifierTypeNode('Foo');
		$node = new NullableTypeNode($identifier);

		$newNodes = $traverser->traverse([$node]);
		$this->assertCount(1, $newNodes);
		$this->assertInstanceOf(NullableTypeNode::class, $newNodes[0]);
		$this->assertNotSame($node, $newNodes[0]);
		$this->assertSame($node, $newNodes[0]->getAttribute(Attribute::ORIGINAL_NODE));

		$this->assertInstanceOf(IdentifierTypeNode::class, $newNodes[0]->type);
		$this->assertNotSame($identifier, $newNodes[0]->type);
		$this->assertSame($identifier, $newNodes[0]->type->getAttribute(Attribute::ORIGINAL_NODE));
	}

}