Skip to content

Commit 83caf56

Browse files
committed
Use #[TestDox(...)] and #[DataProvider(...)] attributes instead of annotations
1 parent b600f77 commit 83caf56

File tree

1 file changed

+38
-60
lines changed

1 file changed

+38
-60
lines changed

tests/E2E/TestCase/RestTraitTestCase.php

Lines changed: 38 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use App\Tests\Utils\PhpUnitUtil;
1212
use Generator;
13+
use PHPUnit\Framework\Attributes\DataProvider;
14+
use PHPUnit\Framework\Attributes\TestDox;
1315
use Symfony\Component\HttpFoundation\Request;
1416
use Symfony\Component\HttpFoundation\Response;
1517
use Throwable;
@@ -53,50 +55,44 @@ abstract public static function getValidUsers(): Generator;
5355
abstract public static function getInvalidUsers(): Generator;
5456

5557
/**
56-
* @dataProvider dataProviderTestThatCountRouteDoesNotAllowNotSupportedHttpMethods
57-
*
5858
* @throws Throwable
59-
*
60-
* @testdox Test that `$m /count` request returns `405` when using invalid user `$u` + `$p`
6159
*/
60+
#[DataProvider('dataProviderTestThatCountRouteDoesNotAllowNotSupportedHttpMethods')]
61+
#[TestDox('Test that `$m /count` request returns `405` when using invalid user `$u` + `$p`')]
6262
public function testThatCountRouteDoesNotAllowNotSupportedHttpMethods(
6363
?string $u = null,
6464
?string $p = null,
65-
?string $m = null
65+
?string $m = null,
6666
): void {
6767
$response = $this->getClientResponse(static::$route . self::END_POINT_COUNT, $u, $p, $m);
6868

6969
static::assertSame(405, $response->getStatusCode(), (string)$response->getContent());
7070
}
7171

7272
/**
73-
* @dataProvider dataProviderTestThatCountRouteWorksWithAllowedHttpMethods
74-
*
7573
* @throws Throwable
76-
*
77-
* @testdox Test that `$m /count` request returns `200` when using valid user `$u` + `$p`
7874
*/
75+
#[DataProvider('dataProviderTestThatCountRouteWorksWithAllowedHttpMethods')]
76+
#[TestDox('Test that `$m /count` request returns `200` when using valid user `$u` + `$p`')]
7977
public function testThatCountRouteWorksWithAllowedHttpMethods(
8078
?string $u = null,
8179
?string $p = null,
82-
?string $m = null
80+
?string $m = null,
8381
): void {
8482
$response = $this->getClientResponse(static::$route . self::END_POINT_COUNT, $u, $p, $m);
8583

8684
static::assertSame(200, $response->getStatusCode(), (string)$response->getContent());
8785
}
8886

8987
/**
90-
* @dataProvider dataProviderTestThatCountRouteDoesNotAllowInvalidUser
91-
*
9288
* @throws Throwable
93-
*
94-
* @testdox Test that `$m /count` request returns `401` or `403` when using invalid user `$u` + `$p`
9589
*/
90+
#[DataProvider('dataProviderTestThatCountRouteDoesNotAllowInvalidUser')]
91+
#[TestDox('Test that `$m /count` request returns `401` or `403` when using invalid user `$u` + `$p`')]
9692
public function testThatCountRouteDoesNotAllowInvalidUser(
9793
?string $u = null,
9894
?string $p = null,
99-
?string $m = null
95+
?string $m = null,
10096
): void {
10197
$response = $this->getClientResponse(static::$route . self::END_POINT_COUNT, $u, $p, $m);
10298

@@ -108,33 +104,29 @@ public function testThatCountRouteDoesNotAllowInvalidUser(
108104
}
109105

110106
/**
111-
* @dataProvider dataProviderTestThatRootRouteDoesNotAllowNotSupportedHttpMethods
112-
*
113107
* @throws Throwable
114-
*
115-
* @testdox Test that `$m /` request returns `405` when using valid user `$u` + `$p`
116108
*/
109+
#[DataProvider('dataProviderTestThatRootRouteDoesNotAllowNotSupportedHttpMethods')]
110+
#[TestDox('Test that `$m /` request returns `405` when using valid user `$u` + `$p`')]
117111
public function testThatRootRouteDoesNotAllowNotSupportedHttpMethods(
118112
?string $u = null,
119113
?string $p = null,
120-
?string $m = null
114+
?string $m = null,
121115
): void {
122116
$response = $this->getClientResponse(static::$route, $u, $p, $m);
123117

124118
static::assertSame(405, $response->getStatusCode(), (string)$response->getContent());
125119
}
126120

127121
/**
128-
* @dataProvider dataProviderTestThatRootRouteWorksWithAllowedHttpMethods
129-
*
130122
* @throws Throwable
131-
*
132-
* @testdox Test that `$m /` request returns `200` or `400` when using valid user `$u` + `$p`
133123
*/
124+
#[DataProvider('dataProviderTestThatRootRouteWorksWithAllowedHttpMethods')]
125+
#[TestDox('Test that `$m /` request returns `200` or `400` when using valid user `$u` + `$p`')]
134126
public function testThatRootRouteWorksWithAllowedHttpMethods(
135127
?string $u = null,
136128
?string $p = null,
137-
?string $m = null
129+
?string $m = null,
138130
): void {
139131
$response = $this->getClientResponse(static::$route, $u, $p, $m);
140132

@@ -144,16 +136,14 @@ public function testThatRootRouteWorksWithAllowedHttpMethods(
144136
}
145137

146138
/**
147-
* @dataProvider dataProviderTestThatRootRouteDoesNotAllowInvalidUser
148-
*
149139
* @throws Throwable
150-
*
151-
* @testdox Test that `$m /` request returns `401` or `403` when using invalid user `$u` + `$p`
152140
*/
141+
#[DataProvider('dataProviderTestThatRootRouteDoesNotAllowInvalidUser')]
142+
#[TestDox('Test that `$m /` request returns `401` or `403` when using invalid user `$u` + `$p`')]
153143
public function testThatRootRouteDoesNotAllowInvalidUser(
154144
?string $u = null,
155145
?string $p = null,
156-
?string $m = null
146+
?string $m = null,
157147
): void {
158148
$response = $this->getClientResponse(static::$route, $u, $p, $m);
159149

@@ -165,35 +155,31 @@ public function testThatRootRouteDoesNotAllowInvalidUser(
165155
}
166156

167157
/**
168-
* @dataProvider dataProviderTestThatRootRouteWithIdDoesNotAllowNotSupportedHttpMethods
169-
*
170158
* @throws Throwable
171-
*
172-
* @testdox Test that `$m /$uuid` request returns `405` when using valid user `$u` + `$p`
173159
*/
160+
#[DataProvider('dataProviderTestThatRootRouteWithIdDoesNotAllowNotSupportedHttpMethods')]
161+
#[TestDox('Test that `$m /$uuid` request returns `405` when using valid user `$u` + `$p`')]
174162
public function testThatRootRouteWithIdDoesNotAllowNotSupportedHttpMethods(
175163
string $uuid,
176164
?string $u = null,
177165
?string $p = null,
178-
?string $m = null
166+
?string $m = null,
179167
): void {
180168
$response = $this->getClientResponse(static::$route . '/' . $uuid, $u, $p, $m);
181169

182170
static::assertSame(405, $response->getStatusCode(), (string)$response->getContent());
183171
}
184172

185173
/**
186-
* @dataProvider dataProviderTestThatRootRouteWithIdWorksWithAllowedHttpMethods
187-
*
188174
* @throws Throwable
189-
*
190-
* @testdox Test that `$m /$uuid` request returns `200` or `400` when using valid user `$u` + `$p`
191175
*/
176+
#[DataProvider('dataProviderTestThatRootRouteWithIdWorksWithAllowedHttpMethods')]
177+
#[TestDox('Test that `$m /$uuid` request returns `200` or `400` when using valid user `$u` + `$p`')]
192178
public function testThatRootRouteWithIdWorksWithAllowedHttpMethods(
193179
string $uuid,
194180
?string $u = null,
195181
?string $p = null,
196-
?string $m = null
182+
?string $m = null,
197183
): void {
198184
$response = $this->getClientResponse(static::$route . '/' . $uuid, $u, $p, $m);
199185

@@ -207,17 +193,15 @@ public function testThatRootRouteWithIdWorksWithAllowedHttpMethods(
207193
}
208194

209195
/**
210-
* @dataProvider dataProviderTestThatRootRouteWithIdDoesNotAllowInvalidUser
211-
*
212196
* @throws Throwable
213-
*
214-
* @testdox Test that `$m /$uuid` request returns `401` or `403` when using invalid user `$u` + `$p`
215197
*/
198+
#[DataProvider('dataProviderTestThatRootRouteWithIdDoesNotAllowInvalidUser')]
199+
#[TestDox('Test that `$m /$uuid` request returns `401` or `403` when using invalid user `$u` + `$p`')]
216200
public function testThatUuidRouteWithIdDoesNotAllowInvalidUser(
217201
string $uuid,
218202
?string $u = null,
219203
?string $p = null,
220-
?string $m = null
204+
?string $m = null,
221205
): void {
222206
$response = $this->getClientResponse(static::$route . '/' . $uuid, $u, $p, $m);
223207

@@ -229,50 +213,44 @@ public function testThatUuidRouteWithIdDoesNotAllowInvalidUser(
229213
}
230214

231215
/**
232-
* @dataProvider dataProviderTestThatIdsRouteDoesNotAllowNotSupportedHttpMethods
233-
*
234216
* @throws Throwable
235-
*
236-
* @testdox Test that `$m /ids` request returns `405` when using valid user `$u` + `$p`
237217
*/
218+
#[DataProvider('dataProviderTestThatIdsRouteDoesNotAllowNotSupportedHttpMethods')]
219+
#[TestDox('Test that `$m /ids` request returns `405` when using valid user `$u` + `$p`')]
238220
public function testThatIdsRouteDoesNotAllowNotSupportedHttpMethods(
239221
?string $u = null,
240222
?string $p = null,
241-
?string $m = null
223+
?string $m = null,
242224
): void {
243225
$response = $this->getClientResponse(static::$route . '/ids', $u, $p, $m);
244226

245227
static::assertSame(405, $response->getStatusCode(), (string)$response->getContent());
246228
}
247229

248230
/**
249-
* @dataProvider dataProviderTestThatIdsRouteWorksWithAllowedHttpMethods
250-
*
251231
* @throws Throwable
252-
*
253-
* @testdox Test that `$m /ids` request returns `200` when using valid user `$u` + `$p`
254232
*/
233+
#[DataProvider('dataProviderTestThatIdsRouteWorksWithAllowedHttpMethods')]
234+
#[TestDox('Test that `$m /ids` request returns `200` when using valid user `$u` + `$p`')]
255235
public function testThatIdsRouteWorksWithAllowedHttpMethods(
256236
?string $u = null,
257237
?string $p = null,
258-
?string $m = null
238+
?string $m = null,
259239
): void {
260240
$response = $this->getClientResponse(static::$route . '/ids', $u, $p, $m);
261241

262242
static::assertSame(200, $response->getStatusCode(), (string)$response->getContent());
263243
}
264244

265245
/**
266-
* @dataProvider dataProviderTestThatIdsRouteDoesNotAllowInvalidUser
267-
*
268246
* @throws Throwable
269-
*
270-
* @testdox Test that `$m /ids` request returns `401` or `403` when using invalid user `$u` + `$p`
271247
*/
248+
#[DataProvider('dataProviderTestThatIdsRouteDoesNotAllowInvalidUser')]
249+
#[TestDox('Test that `$m /ids` request returns `401` or `403` when using invalid user `$u` + `$p`')]
272250
public function testThatIdsRouteDoesNotAllowInvalidUser(
273251
?string $u = null,
274252
?string $p = null,
275-
?string $m = null
253+
?string $m = null,
276254
): void {
277255
$response = $this->getClientResponse(static::$route . '/ids', $u, $p, $m);
278256

0 commit comments

Comments
 (0)