1<?php declare(strict_types=1); 2 3namespace PhpParser\Builder; 4 5use PhpParser\Comment; 6use PhpParser\Node\Arg; 7use PhpParser\Node\Attribute; 8use PhpParser\Node\AttributeGroup; 9use PhpParser\Node\Identifier; 10use PhpParser\Node\Name; 11use PhpParser\Node\Scalar; 12use PhpParser\Node\Scalar\Int_; 13use PhpParser\Node\Stmt; 14 15class EnumCaseTest extends \PHPUnit\Framework\TestCase { 16 public function createEnumCaseBuilder($name) { 17 return new EnumCase($name); 18 } 19 20 public function testDocComment(): void { 21 $node = $this->createEnumCaseBuilder('TEST') 22 ->setDocComment('/** Test */') 23 ->getNode(); 24 25 $this->assertEquals( 26 new Stmt\EnumCase( 27 "TEST", 28 null, 29 [], 30 [ 31 'comments' => [new Comment\Doc('/** Test */')] 32 ] 33 ), 34 $node 35 ); 36 } 37 38 public function testAddAttribute(): void { 39 $attribute = new Attribute( 40 new Name('Attr'), 41 [new Arg(new Int_(1), false, false, [], new Identifier('name'))] 42 ); 43 $attributeGroup = new AttributeGroup([$attribute]); 44 45 $node = $this->createEnumCaseBuilder('ATTR_GROUP') 46 ->addAttribute($attributeGroup) 47 ->getNode(); 48 49 $this->assertEquals( 50 new Stmt\EnumCase( 51 "ATTR_GROUP", 52 null, 53 [$attributeGroup] 54 ), 55 $node 56 ); 57 } 58 59 /** 60 * @dataProvider provideTestDefaultValues 61 */ 62 public function testValues($value, $expectedValueNode): void { 63 $node = $this->createEnumCaseBuilder('TEST') 64 ->setValue($value) 65 ->getNode() 66 ; 67 68 $this->assertEquals($expectedValueNode, $node->expr); 69 } 70 71 public static function provideTestDefaultValues() { 72 return [ 73 [ 74 31415, 75 new Scalar\Int_(31415) 76 ], 77 [ 78 'Hallo World', 79 new Scalar\String_('Hallo World') 80 ], 81 ]; 82 } 83} 84