![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/allure-framework/allure-php-commons/test/Attribute/ |
<?php declare(strict_types=1); namespace Qameta\Allure\Test\Attribute; use Doctrine\Common\Annotations\AnnotationReader; use Qameta\Allure\Attribute\LabelInterface; use Qameta\Allure\Attribute\LinkInterface; use ReflectionMethod; use RuntimeException; use Throwable; use function array_map; trait AnnotationTestTrait { /** * @template T * @param class-string<T> $attributeClass * @param string $demoMethodName * @return T */ protected function getLegacyAttributeInstance(string $attributeClass, string $demoMethodName): object { try { $method = new ReflectionMethod(self::class, $demoMethodName); } catch (Throwable $e) { throw new RuntimeException("Attribute {$attributeClass} not found in {$demoMethodName}", 0, $e); } $reader = new AnnotationReader(); $instance = $reader->getMethodAnnotation($method, $attributeClass); return $instance instanceof $attributeClass ? $instance : throw new RuntimeException("Attribute is not {$attributeClass} instance"); } /** * @template T * @param class-string<T> $attributeClass * @param string $demoMethodName * @return T */ protected function getAttributeInstance(string $attributeClass, string $demoMethodName): object { try { $method = new ReflectionMethod(self::class, $demoMethodName); } catch (Throwable $e) { throw new RuntimeException("Attribute {$attributeClass} not found in {$demoMethodName}", 0, $e); } $attribute = $method->getAttributes($attributeClass)[0] ?? null; return isset($attribute) ? $attribute->newInstance() : throw new RuntimeException("Attribute {$attributeClass} not found in {$demoMethodName}"); } protected function exportLabel(LabelInterface $label): array { return [ 'class' => $label::class, 'name' => $label->getName(), 'value' => $label->getValue(), ]; } protected function exportLabels(LabelInterface ...$labels): array { return array_map( fn (LabelInterface $label) => $this->exportLabel($label), $labels, ); } protected function exportLink(LinkInterface $link): array { return [ 'class' => $link::class, 'type' => $link->getType(), 'value' => $link->getName(), ]; } protected function exportLinks(LinkInterface ...$links): array { return array_map( fn (LinkInterface $link) => $this->exportLink($link), $links, ); } }