From 93fec0ea52b1e6cd9fd5d41437b7fdcae2b61cdd Mon Sep 17 00:00:00 2001 From: Edward Surov Date: Fri, 26 May 2023 16:07:28 +0300 Subject: [PATCH] added attributes for standard labels and attribute sets support (fixes #33, via #58) --- README.md | 55 +++++++++++++++++- src/Allure.php | 5 ++ src/Attribute/AttributeParser.php | 9 ++- src/Attribute/AttributeSetInterface.php | 13 +++++ src/Attribute/Label.php | 5 +- src/Attribute/Layer.php | 16 ++++++ src/Attribute/Lead.php | 16 ++++++ src/Attribute/Owner.php | 16 ++++++ src/Attribute/Package.php | 16 ++++++ src/Attribute/ParentSuite.php | 16 ++++++ src/Attribute/SubSuite.php | 16 ++++++ src/Attribute/Suite.php | 16 ++++++ src/Attribute/Tag.php | 16 ++++++ src/Legacy/Annotation/AllureId.php | 8 +-- src/Legacy/Annotation/Description.php | 8 +-- src/Legacy/Annotation/Epics.php | 8 +-- src/Legacy/Annotation/Features.php | 8 +-- src/Legacy/Annotation/Issues.php | 8 +-- src/Legacy/Annotation/Label.php | 8 +-- src/Legacy/Annotation/Labels.php | 6 +- src/Legacy/Annotation/Parameter.php | 8 +-- src/Legacy/Annotation/Parameters.php | 6 +- src/Legacy/Annotation/Severity.php | 8 +-- src/Legacy/Annotation/Stories.php | 8 +-- src/Legacy/Annotation/TestCaseId.php | 8 +-- src/Legacy/Annotation/Title.php | 8 +-- src/Model/Label.php | 9 +++ test/AllureTest.php | 16 ++++++ test/Attribute/AttributeParserTest.php | 59 +++++++++++++++++++- test/Attribute/LayerTest.php | 39 +++++++++++++ test/Attribute/LeadTest.php | 39 +++++++++++++ test/Attribute/LegacyAttributeReaderTest.php | 5 ++ test/Attribute/OwnerTest.php | 39 +++++++++++++ test/Attribute/PackageTest.php | 39 +++++++++++++ test/Attribute/ParentSuiteTest.php | 39 +++++++++++++ test/Attribute/SubSuiteTest.php | 39 +++++++++++++ test/Attribute/SuiteTest.php | 39 +++++++++++++ test/Attribute/TagTest.php | 39 +++++++++++++ test/Model/LabelTest.php | 50 +++++++++++------ 39 files changed, 694 insertions(+), 72 deletions(-) create mode 100644 src/Attribute/AttributeSetInterface.php create mode 100644 src/Attribute/Layer.php create mode 100644 src/Attribute/Lead.php create mode 100644 src/Attribute/Owner.php create mode 100644 src/Attribute/Package.php create mode 100644 src/Attribute/ParentSuite.php create mode 100644 src/Attribute/SubSuite.php create mode 100644 src/Attribute/Suite.php create mode 100644 src/Attribute/Tag.php create mode 100644 test/Attribute/LayerTest.php create mode 100644 test/Attribute/LeadTest.php create mode 100644 test/Attribute/OwnerTest.php create mode 100644 test/Attribute/PackageTest.php create mode 100644 test/Attribute/ParentSuiteTest.php create mode 100644 test/Attribute/SubSuiteTest.php create mode 100644 test/Attribute/SuiteTest.php create mode 100644 test/Attribute/TagTest.php diff --git a/README.md b/README.md index 21aa2ef..ad61acf 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,56 @@ In order to use this API you simply need to add the following to **composer.json } ``` -## Usage examples -See [allure-phpunit](https://github.com/allure-framework/allure-phpunit) project. +## Custom attributes +You can easily implement custom attributes and use them with your test framework. In most cases you would like +to implement [`Qameta\Allure\Attribute\AttributeSetInterface`](./src/Attribute/AttributeSetInterface.php) that allows to set several attributes at once: + +```php +tags = $tags; + } + + public function getAttributes() : array + { + return [ + new DisplayName($this->displayName), + ...array_map( + fn (string $tag): Tag => new Tag($tag), + $this->tags, + ), + ]; + } +} + +// Example of usage +#[MyAttribute('Test name', 'tag 1', 'tag 2')] +class MyTestClass +{ +} +``` + +You can also implement particular attribute interfaces instead of using one of the standard implementations: + +- [`Qameta\Allure\Attribute\DescriptionInterface`](./src/Attribute/DescriptionInterface.php) +- [`Qameta\Allure\Attribute\DisplayNameInterface`](./src/Attribute/DisplayNameInterface.php) +- [`Qameta\Allure\Attribute\LabelInterface`](./src/Attribute/LabelInterface.php) +- [`Qameta\Allure\Attribute\LinkInterface`](./src/Attribute/LinkInterface.php) +- [`Qameta\Allure\Attribute\ParameterInterface`](./src/Attribute/ParameterInterface.php) + +## Other usage examples +See [allure-phpunit](https://github.com/allure-framework/allure-phpunit) +and [allure-codeception](https://github.com/allure-framework/allure-codeception) projects. diff --git a/src/Allure.php b/src/Allure.php index 1956817..60839f8 100644 --- a/src/Allure.php +++ b/src/Allure.php @@ -193,6 +193,11 @@ public static function package(string $value): void self::getInstance()->doLabel(Label::package($value)); } + public static function layer(string $value): void + { + self::getInstance()->doLabel(Label::layer($value)); + } + public static function label(string $name, string $value): void { self::getInstance()->doLabel( diff --git a/src/Attribute/AttributeParser.php b/src/Attribute/AttributeParser.php index 215ce6d..a70236b 100644 --- a/src/Attribute/AttributeParser.php +++ b/src/Attribute/AttributeParser.php @@ -18,6 +18,8 @@ use ReflectionProperty; use function array_merge; +use function array_pop; +use function array_push; use function array_reverse; use function is_string; @@ -107,7 +109,12 @@ public static function createForChain( private function processAnnotations(AttributeInterface ...$attributes): void { - foreach ($attributes as $attribute) { + while (!empty($attributes)) { + $attribute = array_shift($attributes); + if ($attribute instanceof AttributeSetInterface) { + array_unshift($attributes, ...$attribute->getAttributes()); + continue; + } if ($attribute instanceof DisplayNameInterface) { $this->displayName = $attribute->getValue(); } diff --git a/src/Attribute/AttributeSetInterface.php b/src/Attribute/AttributeSetInterface.php new file mode 100644 index 0000000..bf08120 --- /dev/null +++ b/src/Attribute/AttributeSetInterface.php @@ -0,0 +1,13 @@ + + */ + public function getAttributes(): array; +} diff --git a/src/Attribute/Label.php b/src/Attribute/Label.php index bcaf3b8..34daab8 100644 --- a/src/Attribute/Label.php +++ b/src/Attribute/Label.php @@ -21,11 +21,14 @@ final class Label extends AbstractLabel public const TAG = Model\Label::TAG; public const OWNER = Model\Label::OWNER; public const LEAD = Model\Label::LEAD; + public const PACKAGE = Model\Label::PACKAGE; + public const LAYER = Model\Label::LAYER; + + // Technical labels, set by framework automatically public const HOST = Model\Label::HOST; public const THREAD = Model\Label::THREAD; public const TEST_METHOD = Model\Label::TEST_METHOD; public const TEST_CLASS = Model\Label::TEST_CLASS; - public const PACKAGE = Model\Label::PACKAGE; public const FRAMEWORK = Model\Label::FRAMEWORK; public const LANGUAGE = Model\Label::LANGUAGE; } diff --git a/src/Attribute/Layer.php b/src/Attribute/Layer.php new file mode 100644 index 0000000..c8c4f89 --- /dev/null +++ b/src/Attribute/Layer.php @@ -0,0 +1,16 @@ +value); + return new Attribute\AllureId($this->value); } } diff --git a/src/Legacy/Annotation/Description.php b/src/Legacy/Annotation/Description.php index c435faf..f3928c7 100644 --- a/src/Legacy/Annotation/Description.php +++ b/src/Legacy/Annotation/Description.php @@ -5,14 +5,14 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Description as QametaDescription; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use Yandex\Allure\Adapter\Model\DescriptionType; /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Description} + * @deprecated Use native PHP attribute {@see Attribute\Description} * @psalm-suppress MissingConstructor */ class Description implements LegacyAnnotationInterface @@ -29,10 +29,10 @@ class Description implements LegacyAnnotationInterface */ public string $type = DescriptionType::TEXT; - public function convert(): QametaDescription + public function convert(): Attribute\Description { /** @psalm-suppress DeprecatedClass */ - return new QametaDescription( + return new Attribute\Description( $this->value, DescriptionType::HTML == $this->type, ); diff --git a/src/Legacy/Annotation/Epics.php b/src/Legacy/Annotation/Epics.php index 38d0c50..a0bfaed 100644 --- a/src/Legacy/Annotation/Epics.php +++ b/src/Legacy/Annotation/Epics.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Epic; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Annotation\Epics} + * @deprecated Use native PHP attribute {@see Attribute\Epic} * @psalm-suppress MissingConstructor */ class Epics implements LegacyAnnotationInterface @@ -33,12 +33,12 @@ public function getEpicNames(): array } /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $name) => new Epic($name), + fn (string $name) => new Attribute\Epic($name), $this->epicNames, ); } diff --git a/src/Legacy/Annotation/Features.php b/src/Legacy/Annotation/Features.php index 2adf8c6..9b0ae23 100644 --- a/src/Legacy/Annotation/Features.php +++ b/src/Legacy/Annotation/Features.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Feature; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Annotation\Features} + * @deprecated Use native PHP attribute {@see Attribute\Features} * @psalm-suppress MissingConstructor */ class Features implements LegacyAnnotationInterface @@ -30,12 +30,12 @@ public function getFeatureNames(): array } /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $name) => new Feature($name), + fn (string $name) => new Attribute\Feature($name), $this->featureNames, ); } diff --git a/src/Legacy/Annotation/Issues.php b/src/Legacy/Annotation/Issues.php index df4fdc9..140b118 100644 --- a/src/Legacy/Annotation/Issues.php +++ b/src/Legacy/Annotation/Issues.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Issue; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Annotation\Issues} + * @deprecated Use native PHP attribute {@see Attribute\Issue} * @psalm-suppress MissingConstructor */ class Issues implements LegacyAnnotationInterface @@ -30,12 +30,12 @@ public function getIssueKeys(): array } /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $key) => new Issue($key), + fn (string $key) => new Attribute\Issue($key), $this->issueKeys, ); } diff --git a/src/Legacy/Annotation/Label.php b/src/Legacy/Annotation/Label.php index 342614b..cd22f29 100644 --- a/src/Legacy/Annotation/Label.php +++ b/src/Legacy/Annotation/Label.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Label as QametaLabel; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"METHOD", "ANNOTATION"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Label} + * @deprecated Use native PHP attribute {@see Attribute\Label} * @psalm-suppress MissingConstructor */ class Label implements LegacyAnnotationInterface @@ -31,12 +31,12 @@ class Label implements LegacyAnnotationInterface public array $values; /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $value) => new QametaLabel($this->name, $value), + fn (string $value) => new Attribute\Label($this->name, $value), $this->values, ); } diff --git a/src/Legacy/Annotation/Labels.php b/src/Legacy/Annotation/Labels.php index aab4a58..06fb257 100644 --- a/src/Legacy/Annotation/Labels.php +++ b/src/Legacy/Annotation/Labels.php @@ -4,7 +4,7 @@ namespace Yandex\Allure\Adapter\Annotation; -use Qameta\Allure\Attribute\Label as QametaLabel; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Label} (repeatable). + * @deprecated Use native PHP attribute {@see Attribute\Label} (repeatable). * @psalm-suppress MissingConstructor * @psalm-suppress DeprecatedClass */ @@ -27,7 +27,7 @@ class Labels implements LegacyAnnotationInterface public array $labels; /** - * @return list + * @return list */ public function convert(): array { diff --git a/src/Legacy/Annotation/Parameter.php b/src/Legacy/Annotation/Parameter.php index d23a454..463894e 100644 --- a/src/Legacy/Annotation/Parameter.php +++ b/src/Legacy/Annotation/Parameter.php @@ -5,14 +5,14 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Parameter as QametaParameter; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use Yandex\Allure\Adapter\Model\ParameterKind; /** * @Annotation * @Target({"METHOD", "ANNOTATION"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Parameter} + * @deprecated Use native PHP attribute {@see Attribute\Parameter} * @psalm-suppress MissingConstructor */ class Parameter implements LegacyAnnotationInterface @@ -32,8 +32,8 @@ class Parameter implements LegacyAnnotationInterface */ public string $kind = ParameterKind::ARGUMENT; - public function convert(): QametaParameter + public function convert(): Attribute\Parameter { - return new QametaParameter($this->name, $this->value); + return new Attribute\Parameter($this->name, $this->value); } } diff --git a/src/Legacy/Annotation/Parameters.php b/src/Legacy/Annotation/Parameters.php index 654b049..6c16bda 100644 --- a/src/Legacy/Annotation/Parameters.php +++ b/src/Legacy/Annotation/Parameters.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Parameter as QametaParameter; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Parameter} (repeatable). + * @deprecated Use native PHP attribute {@see Attribute\Parameter} (repeatable). * @psalm-suppress MissingConstructor * @psalm-suppress DeprecatedClass */ @@ -27,7 +27,7 @@ class Parameters implements LegacyAnnotationInterface public array $parameters; /** - * @return list + * @return list */ public function convert(): array { diff --git a/src/Legacy/Annotation/Severity.php b/src/Legacy/Annotation/Severity.php index 0afc58e..686eeee 100644 --- a/src/Legacy/Annotation/Severity.php +++ b/src/Legacy/Annotation/Severity.php @@ -4,14 +4,14 @@ namespace Yandex\Allure\Adapter\Annotation; -use Qameta\Allure\Attribute\Severity as QametaSeverity; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use Yandex\Allure\Adapter\Model\SeverityLevel; /** * @Annotation * @Target({"METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Severity} + * @deprecated Use native PHP attribute {@see Attribute\Severity} */ class Severity implements LegacyAnnotationInterface { @@ -20,8 +20,8 @@ class Severity implements LegacyAnnotationInterface */ public string $level = SeverityLevel::NORMAL; - public function convert(): QametaSeverity + public function convert(): Attribute\Severity { - return new QametaSeverity($this->level); + return new Attribute\Severity($this->level); } } diff --git a/src/Legacy/Annotation/Stories.php b/src/Legacy/Annotation/Stories.php index 74ae3b4..5a08670 100644 --- a/src/Legacy/Annotation/Stories.php +++ b/src/Legacy/Annotation/Stories.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\Story as QametaStory; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\Story} + * @deprecated Use native PHP attribute {@see Attribute\Story} * @psalm-suppress MissingConstructor */ class Stories implements LegacyAnnotationInterface @@ -31,12 +31,12 @@ public function getStories(): array } /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $value) => new QametaStory($value), + fn (string $value) => new Attribute\Story($value), $this->stories, ); } diff --git a/src/Legacy/Annotation/TestCaseId.php b/src/Legacy/Annotation/TestCaseId.php index 988303d..2e958d2 100644 --- a/src/Legacy/Annotation/TestCaseId.php +++ b/src/Legacy/Annotation/TestCaseId.php @@ -5,7 +5,7 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\TmsLink; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; use function array_map; @@ -13,7 +13,7 @@ /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\TmsLink} + * @deprecated Use native PHP attribute {@see Attribute\TmsLink} * @psalm-suppress MissingConstructor */ class TestCaseId implements LegacyAnnotationInterface @@ -31,12 +31,12 @@ public function getTestCaseIds(): array } /** - * @return list + * @return list */ public function convert(): array { return array_map( - fn (string $id) => new TmsLink($id), + fn (string $id) => new Attribute\TmsLink($id), $this->testCaseIds, ); } diff --git a/src/Legacy/Annotation/Title.php b/src/Legacy/Annotation/Title.php index 9017fe8..df67ded 100644 --- a/src/Legacy/Annotation/Title.php +++ b/src/Legacy/Annotation/Title.php @@ -5,13 +5,13 @@ namespace Yandex\Allure\Adapter\Annotation; use Doctrine\Common\Annotations\Annotation\Required; -use Qameta\Allure\Attribute\DisplayName as QametaDisplayName; +use Qameta\Allure\Attribute; use Qameta\Allure\Legacy\Annotation\LegacyAnnotationInterface; /** * @Annotation * @Target({"CLASS", "METHOD"}) - * @deprecated Use native PHP attribute {@see \Qameta\Allure\Attribute\DisplayName} + * @deprecated Use native PHP attribute {@see Attribute\DisplayName} * @psalm-suppress MissingConstructor */ class Title implements LegacyAnnotationInterface @@ -21,8 +21,8 @@ class Title implements LegacyAnnotationInterface */ public string $value; - public function convert(): QametaDisplayName + public function convert(): Attribute\DisplayName { - return new QametaDisplayName($this->value); + return new Attribute\DisplayName($this->value); } } diff --git a/src/Model/Label.php b/src/Model/Label.php index 5cd0aaa..bb10746 100644 --- a/src/Model/Label.php +++ b/src/Model/Label.php @@ -32,6 +32,7 @@ final class Label implements JsonSerializable public const PACKAGE = "package"; public const FRAMEWORK = "framework"; public const LANGUAGE = "language"; + public const LAYER = "layer"; public function __construct( private ?string $name = null, @@ -183,6 +184,14 @@ public static function language(?string $value): self ); } + public static function layer(?string $value): self + { + return new self( + name: self::LAYER, + value: $value, + ); + } + private static function buildPhpVersion(): string { $version = 1 === preg_match('#^\d+\.\d+#', PHP_VERSION, $matches) diff --git a/test/AllureTest.php b/test/AllureTest.php index a6daf85..eddc3d8 100644 --- a/test/AllureTest.php +++ b/test/AllureTest.php @@ -658,6 +658,22 @@ public function testPackage_GivenValue_TestHasMatchingLabel(): void self::assertSame('b', $label?->getValue()); } + public function testLayer_GivenValue_TestHasMatchingLabel(): void + { + $test = new TestResult('a'); + Allure::setLifecycleBuilder( + $this->createLifecycleBuilder( + $this->createResultFactoryWithTest($test), + $this->createLifecycleWithUpdatableTest($test), + ), + ); + + Allure::layer('b'); + $label = $test->getLabels()[0] ?? null; + self::assertSame('layer', $label?->getName()); + self::assertSame('b', $label?->getValue()); + } + public function testLabel_GivenNameAndValue_TestHasMatchingLabel(): void { $test = new TestResult('a'); diff --git a/test/Attribute/AttributeParserTest.php b/test/Attribute/AttributeParserTest.php index f28f7c9..83774de 100644 --- a/test/Attribute/AttributeParserTest.php +++ b/test/Attribute/AttributeParserTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\TestCase; use Qameta\Allure\Attribute; use Qameta\Allure\Attribute\AttributeParser; +use Qameta\Allure\Attribute\AttributeSetInterface; use Qameta\Allure\Setup\LinkTemplateCollectionInterface; use function json_encode; @@ -82,6 +83,34 @@ public function testGetLabels_ConstructedWithLabelAttributes_ReturnsMatchingLabe ); } + public function testGetLabels_ConstructedWithSetOfLabels_ReturnsMatchingLabelModelsInReverseOrder(): void + { + $attributeSet = $this->createStub(AttributeSetInterface::class); + $attributeSet + ->method('getAttributes') + ->willReturn( + [ + new Attribute\Label('a', 'b'), + new Attribute\Label('c', 'd'), + ], + ); + $parser = new AttributeParser( + attributes: [$attributeSet], + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), + ); + + $expectedValue = <<getLabels()), + ); + } + public function testGetParameters_ConstructedWithoutParameterAttributes_ReturnsEmptyList(): void { $parser = new AttributeParser( @@ -93,7 +122,7 @@ public function testGetParameters_ConstructedWithoutParameterAttributes_ReturnsE self::assertEmpty($parser->getParameters()); } - public function testGetParameters_ConstructedWithParameterAttributes_ReturnsMatchingParamsInReverseOrder(): void + public function testGetParameters_ConstructedWithParameterAttributes_ReturnsMatchingParams(): void { $parser = new AttributeParser( attributes: [ @@ -115,6 +144,34 @@ public function testGetParameters_ConstructedWithParameterAttributes_ReturnsMatc ); } + public function testGetParameters_ConstructedWithSetOfParameters_ReturnsMatchingParams(): void + { + $attributeSet = $this->createStub(AttributeSetInterface::class); + $attributeSet + ->method('getAttributes') + ->willReturn( + [ + new Attribute\Parameter('a', 'b', mode: Attribute\ParameterMode::HIDDEN), + new Attribute\Parameter('c', 'd', excluded: true), + ], + ); + $parser = new AttributeParser( + attributes: [$attributeSet], + linkTemplates: $this->createStub(LinkTemplateCollectionInterface::class), + ); + + $expectedValue = <<getParameters()), + ); + } + public function testGetDisplayName_ConstructedWithoutDisplayNameAttribute_ReturnsNull(): void { $parser = new AttributeParser( diff --git a/test/Attribute/LayerTest.php b/test/Attribute/LayerTest.php new file mode 100644 index 0000000..d0a2ca5 --- /dev/null +++ b/test/Attribute/LayerTest.php @@ -0,0 +1,39 @@ +getLayerInstance('demoWithValue'); + self::assertSame('layer', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getLayerInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Layer("a")] + protected function demoWithValue(): void + { + } + + private function getLayerInstance(string $methodName): Layer + { + return $this->getAttributeInstance(Layer::class, $methodName); + } +} diff --git a/test/Attribute/LeadTest.php b/test/Attribute/LeadTest.php new file mode 100644 index 0000000..f463d2f --- /dev/null +++ b/test/Attribute/LeadTest.php @@ -0,0 +1,39 @@ +getLeadInstance('demoWithValue'); + self::assertSame('lead', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getLeadInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Lead("a")] + protected function demoWithValue(): void + { + } + + private function getLeadInstance(string $methodName): Lead + { + return $this->getAttributeInstance(Lead::class, $methodName); + } +} diff --git a/test/Attribute/LegacyAttributeReaderTest.php b/test/Attribute/LegacyAttributeReaderTest.php index 2256474..c8d3a32 100644 --- a/test/Attribute/LegacyAttributeReaderTest.php +++ b/test/Attribute/LegacyAttributeReaderTest.php @@ -9,9 +9,11 @@ use PHPUnit\Framework\TestCase; use Qameta\Allure\Attribute\AttributeReader; use Qameta\Allure\Attribute\AttributeReaderInterface; +use Qameta\Allure\Attribute\AttributeSetInterface; use Qameta\Allure\Attribute\Description; use Qameta\Allure\Attribute\DisplayName; use Qameta\Allure\Attribute\Feature; +use Qameta\Allure\Attribute\Label; use Qameta\Allure\Attribute\LabelInterface; use Qameta\Allure\Attribute\LegacyAttributeReader; use Qameta\Allure\Attribute\Story; @@ -267,6 +269,9 @@ private function exportAnnotation(object $annotation): array $data = [ 'class' => $annotation::class, ]; + if ($annotation instanceof AttributeSetInterface) { + $data['annotations'] = $this->exportAnnotations(...$annotation->getAttributes()); + } if ($annotation instanceof NativePropertyAttribute) { $data['value'] = $annotation->getValue(); } diff --git a/test/Attribute/OwnerTest.php b/test/Attribute/OwnerTest.php new file mode 100644 index 0000000..dc43682 --- /dev/null +++ b/test/Attribute/OwnerTest.php @@ -0,0 +1,39 @@ +getOwnerInstance('demoWithValue'); + self::assertSame('owner', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getOwnerInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Owner("a")] + protected function demoWithValue(): void + { + } + + private function getOwnerInstance(string $methodName): Owner + { + return $this->getAttributeInstance(Owner::class, $methodName); + } +} diff --git a/test/Attribute/PackageTest.php b/test/Attribute/PackageTest.php new file mode 100644 index 0000000..1a9a186 --- /dev/null +++ b/test/Attribute/PackageTest.php @@ -0,0 +1,39 @@ +getPackageInstance('demoWithValue'); + self::assertSame('package', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getPackageInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Package("a")] + protected function demoWithValue(): void + { + } + + private function getPackageInstance(string $methodName): Package + { + return $this->getAttributeInstance(Package::class, $methodName); + } +} diff --git a/test/Attribute/ParentSuiteTest.php b/test/Attribute/ParentSuiteTest.php new file mode 100644 index 0000000..c4dd7a7 --- /dev/null +++ b/test/Attribute/ParentSuiteTest.php @@ -0,0 +1,39 @@ +getParentSuiteInstance('demoWithValue'); + self::assertSame('parentSuite', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getParentSuiteInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[ParentSuite("a")] + protected function demoWithValue(): void + { + } + + private function getParentSuiteInstance(string $methodName): ParentSuite + { + return $this->getAttributeInstance(ParentSuite::class, $methodName); + } +} diff --git a/test/Attribute/SubSuiteTest.php b/test/Attribute/SubSuiteTest.php new file mode 100644 index 0000000..719841d --- /dev/null +++ b/test/Attribute/SubSuiteTest.php @@ -0,0 +1,39 @@ +getSubSuiteInstance('demoWithValue'); + self::assertSame('subSuite', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getSubSuiteInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[SubSuite("a")] + protected function demoWithValue(): void + { + } + + private function getSubSuiteInstance(string $methodName): SubSuite + { + return $this->getAttributeInstance(SubSuite::class, $methodName); + } +} diff --git a/test/Attribute/SuiteTest.php b/test/Attribute/SuiteTest.php new file mode 100644 index 0000000..6960627 --- /dev/null +++ b/test/Attribute/SuiteTest.php @@ -0,0 +1,39 @@ +getSuiteInstance('demoWithValue'); + self::assertSame('suite', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getSuiteInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Suite("a")] + protected function demoWithValue(): void + { + } + + private function getSuiteInstance(string $methodName): Suite + { + return $this->getAttributeInstance(Suite::class, $methodName); + } +} diff --git a/test/Attribute/TagTest.php b/test/Attribute/TagTest.php new file mode 100644 index 0000000..15a751c --- /dev/null +++ b/test/Attribute/TagTest.php @@ -0,0 +1,39 @@ +getTagInstance('demoWithValue'); + self::assertSame('tag', $epic->getName()); + } + + public function testGetValue_WithValue_ReturnsSameString(): void + { + $epic = $this->getTagInstance('demoWithValue'); + self::assertSame('a', $epic->getValue()); + } + + #[Tag("a")] + protected function demoWithValue(): void + { + } + + private function getTagInstance(string $methodName): Tag + { + return $this->getAttributeInstance(Tag::class, $methodName); + } +} diff --git a/test/Model/LabelTest.php b/test/Model/LabelTest.php index aead066..d936172 100644 --- a/test/Model/LabelTest.php +++ b/test/Model/LabelTest.php @@ -49,7 +49,7 @@ public function testSuite_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::suite('a')->getValue()); } - public function testParentSuite_Always_ResultHasSuiteName(): void + public function testParentSuite_Always_ResultHasParentSuiteName(): void { self::assertSame('parentSuite', Label::parentSuite(null)->getName()); } @@ -64,7 +64,7 @@ public function testParentSuite_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::parentSuite('a')->getValue()); } - public function testSubSuite_Always_ResultHasSuiteName(): void + public function testSubSuite_Always_ResultHasSubSuiteName(): void { self::assertSame('subSuite', Label::subSuite(null)->getName()); } @@ -79,7 +79,7 @@ public function testSubSuite_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::subSuite('a')->getValue()); } - public function testEpic_Always_ResultHasSuiteName(): void + public function testEpic_Always_ResultHasEpicName(): void { self::assertSame('epic', Label::epic(null)->getName()); } @@ -94,7 +94,7 @@ public function testEpic_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::epic('a')->getValue()); } - public function testFeature_Always_ResultHasSuiteName(): void + public function testFeature_Always_ResultHasFeatureName(): void { self::assertSame('feature', Label::feature(null)->getName()); } @@ -109,7 +109,7 @@ public function testFeature_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::feature('a')->getValue()); } - public function testStory_Always_ResultHasSuiteName(): void + public function testStory_Always_ResultHasStoryName(): void { self::assertSame('story', Label::story(null)->getName()); } @@ -124,7 +124,7 @@ public function testStory_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::story('a')->getValue()); } - public function testSeverity_Always_ResultHasSuiteName(): void + public function testSeverity_Always_ResultHasSeverityName(): void { self::assertSame('severity', Label::severity(Severity::trivial())->getName()); } @@ -135,7 +135,7 @@ public function testSeverity_GivenNotNull_ResultHasMatchingValue(): void self::assertSame('trivial', Label::severity($value)->getValue()); } - public function testTag_Always_ResultHasSuiteName(): void + public function testTag_Always_ResultHasTagName(): void { self::assertSame('tag', Label::tag(null)->getName()); } @@ -150,7 +150,7 @@ public function testTag_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::tag('a')->getValue()); } - public function testOwner_Always_ResultHasSuiteName(): void + public function testOwner_Always_ResultHasOwnerName(): void { self::assertSame('owner', Label::owner(null)->getName()); } @@ -165,7 +165,7 @@ public function testOwner_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::owner('a')->getValue()); } - public function testLead_Always_ResultHasSuiteName(): void + public function testLead_Always_ResultHasLeadName(): void { self::assertSame('lead', Label::lead(null)->getName()); } @@ -180,7 +180,7 @@ public function testLead_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::lead('a')->getValue()); } - public function testHost_Always_ResultHasSuiteName(): void + public function testHost_Always_ResultHasHostName(): void { self::assertSame('host', Label::host(null)->getName()); } @@ -195,7 +195,7 @@ public function testHost_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::host('a')->getValue()); } - public function testThread_Always_ResultHasSuiteName(): void + public function testThread_Always_ResultHasThreadName(): void { self::assertSame('thread', Label::thread(null)->getName()); } @@ -210,7 +210,7 @@ public function testThread_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::thread('a')->getValue()); } - public function testTestMethod_Always_ResultHasSuiteName(): void + public function testTestMethod_Always_ResultHasTestMethodName(): void { self::assertSame('testMethod', Label::testMethod(null)->getName()); } @@ -225,7 +225,7 @@ public function testTestMethod_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::testMethod('a')->getValue()); } - public function testTestClass_Always_ResultHasSuiteName(): void + public function testTestClass_Always_ResultHasTestClassName(): void { self::assertSame('testClass', Label::testClass(null)->getName()); } @@ -240,7 +240,7 @@ public function testTestClass_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::testClass('a')->getValue()); } - public function testPackage_Always_ResultHasSuiteName(): void + public function testPackage_Always_ResultHasPackageName(): void { self::assertSame('package', Label::package(null)->getName()); } @@ -255,7 +255,7 @@ public function testPackage_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::package('a')->getValue()); } - public function testFramework_Always_ResultHasSuiteName(): void + public function testFramework_Always_ResultHasFrameworkName(): void { self::assertSame('framework', Label::framework(null)->getName()); } @@ -270,12 +270,12 @@ public function testFramework_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::framework('a')->getValue()); } - public function testLanguage_Always_ResultHasSuiteName(): void + public function testLanguage_Always_ResultHasLanguageName(): void { self::assertSame('language', Label::language(null)->getName()); } - public function testLanguage_GivenNull_ResultIsPhpWithCurrentVersion(): void + public function testLanguage_GivenNull_ResultHasPhpWithCurrentVersionValue(): void { $value = Label::language(null)->getValue(); self::assertIsString($value); @@ -287,6 +287,22 @@ public function testLanguage_GivenNotNull_ResultHasSameValue(): void self::assertSame('a', Label::language('a')->getValue()); } + public function testLayer_Always_ResultHasLayerName(): void + { + self::assertSame('layer', Label::layer(null)->getName()); + } + + public function testLayer_GivenNull_ResultHasNullValue(): void + { + $value = Label::layer(null)->getValue(); + self::assertNull($value); + } + + public function testLayer_GivenNotNull_ResultHasSameValue(): void + { + self::assertSame('a', Label::layer('a')->getValue()); + } + public function testGetName_ConstructedWithoutName_ReturnsNull(): void { $label = new Label();