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 5a95188 commit 0d34d10
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 31 deletions.
13 changes: 13 additions & 0 deletions tests/unit/Component/Tests/Annotation/Attr1.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Imi\Test\Component\Tests\Annotation;

#[\Attribute()]
class Attr1
{
public function __construct(public string $id = '', public array $arr = [])
{
}
}
16 changes: 16 additions & 0 deletions tests/unit/Component/Tests/Annotation/Attr2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Imi\Test\Component\Tests\Annotation;

#[\Attribute()]
class Attr2
{
/**
* @param Attr1[] $attr1s
*/
public function __construct(public Attr1 $attr1, public array $attr1s)
{
}
}
9 changes: 9 additions & 0 deletions tests/unit/Component/Tests/Annotation/NotAttr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Imi\Test\Component\Tests\Annotation;

class NotAttr
{
}
42 changes: 11 additions & 31 deletions tests/unit/Component/Tests/Util/AnnotationUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

use Imi\Bean\Util\AttributeUtil;
use Imi\Test\BaseTest;
use Imi\Test\Component\Tests\Annotation\Attr1;
use Imi\Test\Component\Tests\Annotation\Attr2;
use Imi\Test\Component\Tests\Annotation\NotAttr;

class AttributeUtilTest extends BaseTest
class AnnotationUtilTest extends BaseTest
{
public function testGenerateAttributesCode(): void
{
Expand All @@ -18,18 +21,18 @@ public function testGenerateAttributesCode(): void
new Attr1(id: 'c'),
]),
];
$this->assertEquals(<<<'CODE'
$this->assertStringEqualsStringIgnoringLineEndings(<<<'CODE'
#[
\Imi\Test\Component\Tests\Util\Attr1(),
\Imi\Test\Component\Tests\Util\Attr2(attr1: [
new \Imi\Test\Component\Tests\Util\Attr1(id: 'a\\1', arr: [
\Imi\Test\Component\Tests\Annotation\Attr1(),
\Imi\Test\Component\Tests\Annotation\Attr2(attr1: [
new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'a\\1', arr: [
1,
2,
3
])
], attr1s: [
new \Imi\Test\Component\Tests\Util\Attr1(id: 'b'),
new \Imi\Test\Component\Tests\Util\Attr1(id: 'c')
new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'b'),
new \Imi\Test\Component\Tests\Annotation\Attr1(id: 'c')
])
]
CODE, AttributeUtil::generateAttributesCode($attributes));
Expand All @@ -38,30 +41,7 @@ public function testGenerateAttributesCode(): void
public function testGenerateAttributesCodeNotAttr(): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Class Imi\Test\Component\Tests\Util\NotAttr does not an Attribute');
$this->expectExceptionMessage('Class Imi\Test\Component\Tests\Annotation\NotAttr does not an Attribute');
AttributeUtil::generateAttributesCode(new NotAttr());
}
}

#[\Attribute()]
class Attr1
{
public function __construct(public string $id = '', public array $arr = [])
{
}
}

#[\Attribute()]
class Attr2
{
/**
* @param Attr1[] $attr1s
*/
public function __construct(public Attr1 $attr1, public array $attr1s)
{
}
}

class NotAttr
{
}

0 comments on commit 0d34d10

Please sign in to comment.