-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathUnitProvider.php
More file actions
129 lines (111 loc) · 3.28 KB
/
Copy pathUnitProvider.php
File metadata and controls
129 lines (111 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
declare(strict_types=1);
namespace Qameta\Allure\Codeception\Internal;
use Closure;
use Codeception\Test\TestCaseWrapper;
use Qameta\Allure\Attribute\AttributeParser;
use Qameta\Allure\Setup\LinkTemplateCollectionInterface;
use Qameta\Allure\Model\ModelProviderInterface;
use Qameta\Allure\Model\Parameter;
use ReflectionException;
use ReflectionMethod;
use function array_shift;
use function is_int;
/**
* @internal
*/
final class UnitProvider implements ModelProviderInterface
{
/**
* @param TestCaseWrapper $test
* @param LinkTemplateCollectionInterface $linkTemplates
*/
public function __construct(
private TestCaseWrapper $test,
LinkTemplateCollectionInterface $linkTemplates,
) {
}
/**
* @param TestCaseWrapper $test
* @param LinkTemplateCollectionInterface $linkTemplates
* @throws ReflectionException
* @return list<ModelProviderInterface>
*/
public static function createForChain(TestCaseWrapper $test, LinkTemplateCollectionInterface $linkTemplates): array
{
$fields = $test->getReportFields();
/** @var class-string $class */
$class = $fields['class'] ?? null;
/** @var Closure|callable-string|null $methodOrFunction */
$methodOrFunction = $test->getMetadata()->getName();
return [
...AttributeParser::createForChain(
classOrObject: $class,
methodOrFunction: $methodOrFunction,
linkTemplates: $linkTemplates,
),
new self($test, $linkTemplates),
];
}
#[\Override]
public function getLinks(): array
{
return [];
}
#[\Override]
public function getLabels(): array
{
return [];
}
/**
* @throws ReflectionException
*/
#[\Override]
public function getParameters(): array
{
$testMetadata = $this->test->getMetadata();
if (null === $testMetadata->getIndex()) {
return [];
}
$testCase = $this->test->getTestCase();
$dataMethod = new ReflectionMethod($testCase, 'getProvidedData');
$dataMethod->setAccessible(true);
$methodName = $testMetadata->getName();
$testMethod = new ReflectionMethod($testCase, $methodName);
$argNames = $testMethod->getParameters();
$params = [];
/**
* @var array-key $key
* @var mixed $param
*/
foreach ($dataMethod->invoke($testCase) as $key => $param) {
$argName = array_shift($argNames);
$name = $argName?->getName() ?? $key;
$params[] = new Parameter(
is_int($name) ? "#$name" : $name,
ArgumentAsString::get($param),
);
}
return $params;
}
#[\Override]
public function getDisplayName(): ?string
{
return $this->test->getMetadata()->getName();
}
#[\Override]
public function getDescription(): ?string
{
return null;
}
#[\Override]
public function getDescriptionHtml(): ?string
{
return null;
}
#[\Override]
public function getFullName(): ?string
{
return $this->test->getTestCase()::class . '::' . $this->test->getMetadata()->getName();
}
}