Skip to content

Commit

Permalink
完善测试
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Oct 27, 2023
1 parent 0d34d10 commit 96814ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tests/unit/Component/Tests/Annotation/Attr2.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
#[\Attribute()]
class Attr2
{
public ?Attr1 $attr1 = null;

/**
* @param Attr1[] $attr1s
*/
public function __construct(public Attr1 $attr1, public array $attr1s)
public function __construct(?Attr1 $attr1 = null, public array $attr1s = [])
{
// 为了测试覆盖,$attr1s 特意不用属性提升写法
$this->attr1 = $attr1;
}
}
10 changes: 9 additions & 1 deletion tests/unit/Component/Tests/Util/AnnotationUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testGenerateAttributesCode(): void
new Attr1(id: 'b'),
new Attr1(id: 'c'),
]),
new Attr2(),
];
$this->assertStringEqualsStringIgnoringLineEndings(<<<'CODE'
#[
Expand All @@ -33,9 +34,16 @@ public function testGenerateAttributesCode(): void
], attr1s: [
new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'b'),
new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'c')
])
]),
\Imi\Test\Component\Tests\Annotation\Attr2()
]
CODE, AttributeUtil::generateAttributesCode($attributes));

$this->assertStringEqualsStringIgnoringLineEndings(<<<'CODE'
#[
\Imi\Test\Component\Tests\Annotation\Attr1()
]
CODE, AttributeUtil::generateAttributesCode(new Attr1()));
}

public function testGenerateAttributesCodeNotAttr(): void
Expand Down

0 comments on commit 96814ab

Please sign in to comment.