forked from sebastianbergmann/phpunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMethod.php
More file actions
170 lines (144 loc) · 3.94 KB
/
TestMethod.php
File metadata and controls
170 lines (144 loc) · 3.94 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\Event\Code;
use function is_int;
use function sprintf;
use PHPUnit\Event\TestData\TestDataCollection;
use PHPUnit\Metadata\MetadataCollection;
/**
* @immutable
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
*/
final readonly class TestMethod extends Test
{
/**
* @var class-string
*/
private string $className;
/**
* @var non-empty-string
*/
private string $methodName;
/**
* @var non-negative-int
*/
private int $line;
private TestDox $testDox;
private MetadataCollection $metadata;
private TestDataCollection $testData;
/**
* @var positive-int
*/
private int $repeatAttemptNumber;
/**
* @param class-string $className
* @param non-empty-string $methodName
* @param non-empty-string $file
* @param non-negative-int $line
* @param positive-int $repeatAttemptNumber
*/
public function __construct(string $className, string $methodName, string $file, int $line, TestDox $testDox, MetadataCollection $metadata, TestDataCollection $testData, int $repeatAttemptNumber = 1)
{
parent::__construct($file);
$this->className = $className;
$this->methodName = $methodName;
$this->line = $line;
$this->testDox = $testDox;
$this->metadata = $metadata;
$this->testData = $testData;
$this->repeatAttemptNumber = $repeatAttemptNumber;
}
/**
* @return class-string
*/
public function className(): string
{
return $this->className;
}
/**
* @return non-empty-string
*/
public function methodName(): string
{
return $this->methodName;
}
/**
* @return non-negative-int
*/
public function line(): int
{
return $this->line;
}
public function testDox(): TestDox
{
return $this->testDox;
}
public function metadata(): MetadataCollection
{
return $this->metadata;
}
public function testData(): TestDataCollection
{
return $this->testData;
}
public function isTestMethod(): true
{
return true;
}
/**
* @return non-empty-string
*/
public function id(): string
{
$buffer = $this->className . '::' . $this->methodName;
if ($this->testData()->hasDataFromDataProvider()) {
$buffer .= '#' . $this->testData->dataFromDataProvider()->dataSetName();
}
return $buffer;
}
/**
* @return non-empty-string
*/
public function nameWithClass(): string
{
return $this->className . '::' . $this->name();
}
/**
* @return non-empty-string
*/
public function name(): string
{
if (!$this->testData->hasDataFromDataProvider()) {
$name = $this->methodName;
if ($this->repeatAttemptNumber !== 1) {
$name .= " (repeat attempt #{$this->repeatAttemptNumber})";
}
return $name;
}
$dataSetName = $this->testData->dataFromDataProvider()->dataSetName();
if (is_int($dataSetName)) {
$dataSetName = sprintf(
' with data set #%d',
$dataSetName,
);
} else {
$dataSetName = sprintf(
' with data set "%s"',
$dataSetName,
);
}
$name = $this->methodName . $dataSetName;
if ($this->repeatAttemptNumber !== 1) {
$name .= " (repeat attempt #{$this->repeatAttemptNumber})";
}
return $name;
}
}