Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 72a82c3

Browse filesBrowse files
committed
minor #39917 [Uid] split success and failure tests (xabbuh)
This PR was merged into the 5.3-dev branch. Discussion ---------- [Uid] split success and failure tests | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | Commits ------- ea9624e split success and failure tests
2 parents f52ef5d + ea9624e commit 72a82c3
Copy full SHA for 72a82c3

File tree

2 files changed

+128
-96
lines changed
Filter options

2 files changed

+128
-96
lines changed

‎src/Symfony/Component/Uid/Tests/UlidTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Tests/UlidTest.php
+64-48Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,25 @@ public function testFromBinary()
125125
Ulid::fromString("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"),
126126
Ulid::fromBinary("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08")
127127
);
128+
}
128129

129-
foreach ([
130-
'01EW2RYKDCT2SAK454KBR2QG08',
131-
'1BVXue8CnY8ogucrHX3TeF',
132-
'0177058f-4dac-d0b2-a990-a49af02bc008',
133-
] as $ulid) {
134-
try {
135-
Ulid::fromBinary($ulid);
130+
/**
131+
* @dataProvider provideInvalidBinaryFormat
132+
*/
133+
public function testFromBinaryInvalidFormat(string $ulid)
134+
{
135+
$this->expectException(\InvalidArgumentException::class);
136136

137-
$this->fail();
138-
} catch (\Throwable $e) {
139-
}
137+
Ulid::fromBinary($ulid);
138+
}
140139

141-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
142-
}
140+
public function provideInvalidBinaryFormat()
141+
{
142+
return [
143+
['01EW2RYKDCT2SAK454KBR2QG08'],
144+
['1BVXue8CnY8ogucrHX3TeF'],
145+
['0177058f-4dac-d0b2-a990-a49af02bc008'],
146+
];
143147
}
144148

145149
public function testFromBase58()
@@ -148,21 +152,25 @@ public function testFromBase58()
148152
Ulid::fromString('1BVXue8CnY8ogucrHX3TeF'),
149153
Ulid::fromBase58('1BVXue8CnY8ogucrHX3TeF')
150154
);
155+
}
151156

152-
foreach ([
153-
"\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08",
154-
'01EW2RYKDCT2SAK454KBR2QG08',
155-
'0177058f-4dac-d0b2-a990-a49af02bc008',
156-
] as $ulid) {
157-
try {
158-
Ulid::fromBase58($ulid);
157+
/**
158+
* @dataProvider provideInvalidBase58Format
159+
*/
160+
public function testFromBase58InvalidFormat(string $ulid)
161+
{
162+
$this->expectException(\InvalidArgumentException::class);
159163

160-
$this->fail();
161-
} catch (\Throwable $e) {
162-
}
164+
Ulid::fromBase58($ulid);
165+
}
163166

164-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
165-
}
167+
public function provideInvalidBase58Format()
168+
{
169+
return [
170+
["\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"],
171+
['01EW2RYKDCT2SAK454KBR2QG08'],
172+
['0177058f-4dac-d0b2-a990-a49af02bc008'],
173+
];
166174
}
167175

168176
public function testFromBase32()
@@ -171,21 +179,25 @@ public function testFromBase32()
171179
Ulid::fromString('01EW2RYKDCT2SAK454KBR2QG08'),
172180
Ulid::fromBase32('01EW2RYKDCT2SAK454KBR2QG08')
173181
);
182+
}
174183

175-
foreach ([
176-
"\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08",
177-
'1BVXue8CnY8ogucrHX3TeF',
178-
'0177058f-4dac-d0b2-a990-a49af02bc008',
179-
] as $ulid) {
180-
try {
181-
Ulid::fromBase32($ulid);
184+
/**
185+
* @dataProvider provideInvalidBase32Format
186+
*/
187+
public function testFromBase32InvalidFormat(string $ulid)
188+
{
189+
$this->expectException(\InvalidArgumentException::class);
182190

183-
$this->fail();
184-
} catch (\Throwable $e) {
185-
}
191+
Ulid::fromBase32($ulid);
192+
}
186193

187-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
188-
}
194+
public function provideInvalidBase32Format()
195+
{
196+
return [
197+
["\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"],
198+
['1BVXue8CnY8ogucrHX3TeF'],
199+
['0177058f-4dac-d0b2-a990-a49af02bc008'],
200+
];
189201
}
190202

191203
public function testFromRfc4122()
@@ -194,20 +206,24 @@ public function testFromRfc4122()
194206
Ulid::fromString('0177058f-4dac-d0b2-a990-a49af02bc008'),
195207
Ulid::fromRfc4122('0177058f-4dac-d0b2-a990-a49af02bc008')
196208
);
209+
}
197210

198-
foreach ([
199-
"\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08",
200-
'01EW2RYKDCT2SAK454KBR2QG08',
201-
'1BVXue8CnY8ogucrHX3TeF',
202-
] as $ulid) {
203-
try {
204-
Ulid::fromRfc4122($ulid);
211+
/**
212+
* @dataProvider provideInvalidRfc4122Format
213+
*/
214+
public function testFromRfc4122InvalidFormat(string $ulid)
215+
{
216+
$this->expectException(\InvalidArgumentException::class);
205217

206-
$this->fail();
207-
} catch (\Throwable $e) {
208-
}
218+
Ulid::fromRfc4122($ulid);
219+
}
209220

210-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
211-
}
221+
public function provideInvalidRfc4122Format()
222+
{
223+
return [
224+
["\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"],
225+
['01EW2RYKDCT2SAK454KBR2QG08'],
226+
['1BVXue8CnY8ogucrHX3TeF'],
227+
];
212228
}
213229
}

‎src/Symfony/Component/Uid/Tests/UuidTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Uid/Tests/UuidTest.php
+64-48Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,25 @@ public function testFromBinary()
200200
Uuid::fromString("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08"),
201201
Uuid::fromBinary("\x01\x77\x05\x8F\x4D\xAC\xD0\xB2\xA9\x90\xA4\x9A\xF0\x2B\xC0\x08")
202202
);
203+
}
203204

204-
foreach ([
205-
'01EW2RYKDCT2SAK454KBR2QG08',
206-
'1BVXue8CnY8ogucrHX3TeF',
207-
'0177058f-4dac-d0b2-a990-a49af02bc008',
208-
] as $ulid) {
209-
try {
210-
Uuid::fromBinary($ulid);
205+
/**
206+
* @dataProvider provideInvalidBinaryFormat
207+
*/
208+
public function testFromBinaryInvalidFormat(string $ulid)
209+
{
210+
$this->expectException(\InvalidArgumentException::class);
211211

212-
$this->fail();
213-
} catch (\Throwable $e) {
214-
}
212+
Uuid::fromBinary($ulid);
213+
}
215214

216-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
217-
}
215+
public function provideInvalidBinaryFormat()
216+
{
217+
return [
218+
['01EW2RYKDCT2SAK454KBR2QG08'],
219+
['1BVXue8CnY8ogucrHX3TeF'],
220+
['0177058f-4dac-d0b2-a990-a49af02bc008'],
221+
];
218222
}
219223

220224
public function testFromBase58()
@@ -223,21 +227,25 @@ public function testFromBase58()
223227
UuidV1::fromString('94fSqj9oxGtsNbkfQNntwx'),
224228
UuidV1::fromBase58('94fSqj9oxGtsNbkfQNntwx')
225229
);
230+
}
226231

227-
foreach ([
228-
"\x41\x4C\x08\x92\x57\x1B\x11\xEB\xBF\x70\x93\xF9\xB0\x82\x2C\x57",
229-
'219G494NRV27NVYW4KZ6R84B2Q',
230-
'414c0892-571b-11eb-bf70-93f9b0822c57',
231-
] as $ulid) {
232-
try {
233-
UuidV1::fromBase58($ulid);
232+
/**
233+
* @dataProvider provideInvalidBase58Format
234+
*/
235+
public function testFromBase58InvalidFormat(string $ulid)
236+
{
237+
$this->expectException(\InvalidArgumentException::class);
234238

235-
$this->fail();
236-
} catch (\Throwable $e) {
237-
}
239+
Uuid::fromBase58($ulid);
240+
}
238241

239-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
240-
}
242+
public function provideInvalidBase58Format()
243+
{
244+
return [
245+
["\x41\x4C\x08\x92\x57\x1B\x11\xEB\xBF\x70\x93\xF9\xB0\x82\x2C\x57"],
246+
['219G494NRV27NVYW4KZ6R84B2Q'],
247+
['414c0892-571b-11eb-bf70-93f9b0822c57'],
248+
];
241249
}
242250

243251
public function testFromBase32()
@@ -246,21 +254,25 @@ public function testFromBase32()
246254
UuidV5::fromString('2VN0S74HBDBB0AQRXAHFVG35KK'),
247255
UuidV5::fromBase32('2VN0S74HBDBB0AQRXAHFVG35KK')
248256
);
257+
}
249258

250-
foreach ([
251-
"\x5B\xA8\x32\x72\x45\x6D\x5A\xC0\xAB\xE3\xAA\x8B\xF7\x01\x96\x73",
252-
'CKTRYycTes6WAqSQJsTDaz',
253-
'5ba83272-456d-5ac0-abe3-aa8bf7019673',
254-
] as $ulid) {
255-
try {
256-
Ulid::fromBase32($ulid);
259+
/**
260+
* @dataProvider provideInvalidBase32Format
261+
*/
262+
public function testFromBase32InvalidFormat(string $ulid)
263+
{
264+
$this->expectException(\InvalidArgumentException::class);
257265

258-
$this->fail();
259-
} catch (\Throwable $e) {
260-
}
266+
Uuid::fromBase32($ulid);
267+
}
261268

262-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
263-
}
269+
public function provideInvalidBase32Format()
270+
{
271+
return [
272+
["\x5B\xA8\x32\x72\x45\x6D\x5A\xC0\xAB\xE3\xAA\x8B\xF7\x01\x96\x73"],
273+
['CKTRYycTes6WAqSQJsTDaz'],
274+
['5ba83272-456d-5ac0-abe3-aa8bf7019673'],
275+
];
264276
}
265277

266278
public function testFromRfc4122()
@@ -269,20 +281,24 @@ public function testFromRfc4122()
269281
UuidV6::fromString('1eb571b4-14c0-6893-bf70-2d4c83cf755a'),
270282
UuidV6::fromRfc4122('1eb571b4-14c0-6893-bf70-2d4c83cf755a')
271283
);
284+
}
272285

273-
foreach ([
274-
"\x1E\xB5\x71\xB4\x14\xC0\x68\x93\xBF\x70\x2D\x4C\x83\xCF\x75\x5A",
275-
'0YPNRV8560D29VYW1D9J1WYXAT',
276-
'4nwTLZ2TdMtTVDE5AwVjaR',
277-
] as $ulid) {
278-
try {
279-
Ulid::fromRfc4122($ulid);
286+
/**
287+
* @dataProvider provideInvalidRfc4122Format
288+
*/
289+
public function testFromRfc4122InvalidFormat(string $ulid)
290+
{
291+
$this->expectException(\InvalidArgumentException::class);
280292

281-
$this->fail();
282-
} catch (\Throwable $e) {
283-
}
293+
Uuid::fromRfc4122($ulid);
294+
}
284295

285-
$this->assertInstanceOf(\InvalidArgumentException::class, $e);
286-
}
296+
public function provideInvalidRfc4122Format()
297+
{
298+
return [
299+
["\x1E\xB5\x71\xB4\x14\xC0\x68\x93\xBF\x70\x2D\x4C\x83\xCF\x75\x5A"],
300+
['0YPNRV8560D29VYW1D9J1WYXAT'],
301+
['4nwTLZ2TdMtTVDE5AwVjaR'],
302+
];
287303
}
288304
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.