Skip to content

Commit 07cba7f

Browse files
committed
coding style: reformatted Assert::exception
1 parent 760576d commit 07cba7f

File tree

1 file changed

+59
-37
lines changed

1 file changed

+59
-37
lines changed

tests/Parser.phpt

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ test('alias', function () {
5757
Assert::same(['--param' => true], $cmd->parse(['-p']));
5858
Assert::same(['--param' => true], $cmd->parse(['--param']));
5959
Assert::same(['--param' => true], $cmd->parse(explode(' ', '-p --param')));
60-
Assert::exception(function () use ($cmd) {
61-
$cmd->parse(['-p=val']);
62-
}, Throwable::class, 'Option --param has not argument.');
60+
Assert::exception(
61+
fn() => $cmd->parse(['-p=val']),
62+
Throwable::class,
63+
'Option --param has not argument.',
64+
);
6365

6466
$cmd = new Parser('
6567
-p --param
@@ -85,13 +87,17 @@ test('argument', function () {
8587
Assert::same(['-p' => 'val'], $cmd->parse(explode(' ', '-p=val')));
8688
Assert::same(['-p' => 'val2'], $cmd->parse(explode(' ', '-p val1 -p val2')));
8789

88-
Assert::exception(function () use ($cmd) {
89-
$cmd->parse(['-p']);
90-
}, Throwable::class, 'Option -p requires argument.');
90+
Assert::exception(
91+
fn() => $cmd->parse(['-p']),
92+
Throwable::class,
93+
'Option -p requires argument.',
94+
);
9195

92-
Assert::exception(function () use ($cmd) {
93-
$cmd->parse(['-p', '-a']);
94-
}, Throwable::class, 'Option -p requires argument.');
96+
Assert::exception(
97+
fn() => $cmd->parse(['-p', '-a']),
98+
Throwable::class,
99+
'Option -p requires argument.',
100+
);
95101

96102

97103
$cmd = new Parser('
@@ -156,13 +162,17 @@ test('enumerates', function () {
156162
');
157163

158164
Assert::same(['-p' => null], $cmd->parse([]));
159-
Assert::exception(function () use ($cmd) {
160-
$cmd->parse(['-p']);
161-
}, Throwable::class, 'Option -p requires argument.');
165+
Assert::exception(
166+
fn() => $cmd->parse(['-p']),
167+
Throwable::class,
168+
'Option -p requires argument.',
169+
);
162170
Assert::same(['-p' => 'a'], $cmd->parse(explode(' ', '-p a')));
163-
Assert::exception(function () use ($cmd) {
164-
$cmd->parse(explode(' ', '-p foo'));
165-
}, Throwable::class, 'Value of option -p must be a, or b, or c.');
171+
Assert::exception(
172+
fn() => $cmd->parse(explode(' ', '-p foo')),
173+
Throwable::class,
174+
'Value of option -p must be a, or b, or c.',
175+
);
166176

167177

168178
$cmd = new Parser('
@@ -172,9 +182,11 @@ test('enumerates', function () {
172182
Assert::same(['-p' => null], $cmd->parse([]));
173183
Assert::same(['-p' => true], $cmd->parse(['-p']));
174184
Assert::same(['-p' => 'a'], $cmd->parse(explode(' ', '-p a')));
175-
Assert::exception(function () use ($cmd) {
176-
$cmd->parse(explode(' ', '-p foo'));
177-
}, Throwable::class, 'Value of option -p must be a, or b, or c.');
185+
Assert::exception(
186+
fn() => $cmd->parse(explode(' ', '-p foo')),
187+
Throwable::class,
188+
'Value of option -p must be a, or b, or c.',
189+
);
178190
});
179191

180192

@@ -186,9 +198,11 @@ test('realpath', function () {
186198
'-p' => [Parser::RealPath => true],
187199
]);
188200

189-
Assert::exception(function () use ($cmd) {
190-
$cmd->parse(['-p', 'xyz']);
191-
}, Throwable::class, "File path 'xyz' not found.");
201+
Assert::exception(
202+
fn() => $cmd->parse(['-p', 'xyz']),
203+
Throwable::class,
204+
"File path 'xyz' not found.",
205+
);
192206
Assert::same(['-p' => __FILE__], $cmd->parse(['-p', __FILE__]));
193207
});
194208

@@ -198,7 +212,7 @@ test('normalizer', function () {
198212
$cmd = new Parser('
199213
-p param
200214
', [
201-
'-p' => [Parser::Normalizer => function ($arg) { return "$arg-normalized"; }],
215+
'-p' => [Parser::Normalizer => fn($arg) => "$arg-normalized"],
202216
]);
203217

204218
Assert::same(['-p' => 'val-normalized'], $cmd->parse(explode(' ', '-p val')));
@@ -207,7 +221,7 @@ test('normalizer', function () {
207221
$cmd = new Parser('
208222
-p <a|b>
209223
', [
210-
'-p' => [Parser::Normalizer => function () { return 'a'; }],
224+
'-p' => [Parser::Normalizer => fn() => 'a'],
211225
]);
212226

213227
Assert::same(['-p' => 'a'], $cmd->parse(explode(' ', '-p xxx')));
@@ -216,7 +230,7 @@ test('normalizer', function () {
216230
$cmd = new Parser('
217231
-p <a|b>
218232
', [
219-
'-p' => [Parser::Normalizer => function () { return ['a', 'foo']; }],
233+
'-p' => [Parser::Normalizer => fn() => ['a', 'foo']],
220234
]);
221235

222236
Assert::same(['-p' => ['a', 'foo']], $cmd->parse(explode(' ', '-p xxx')));
@@ -231,13 +245,17 @@ test('positional arguments', function () {
231245

232246
Assert::same(['pos' => 'val'], $cmd->parse(['val']));
233247

234-
Assert::exception(function () use ($cmd) {
235-
$cmd->parse([]);
236-
}, Throwable::class, 'Missing required argument <pos>.');
248+
Assert::exception(
249+
fn() => $cmd->parse([]),
250+
Throwable::class,
251+
'Missing required argument <pos>.',
252+
);
237253

238-
Assert::exception(function () use ($cmd) {
239-
$cmd->parse(['val1', 'val2']);
240-
}, Throwable::class, 'Unexpected parameter val2.');
254+
Assert::exception(
255+
fn() => $cmd->parse(['val1', 'val2']),
256+
Throwable::class,
257+
'Unexpected parameter val2.',
258+
);
241259

242260
$cmd = new Parser('', [
243261
'pos' => [Parser::Repeatable => true],
@@ -266,11 +284,15 @@ test('errors', function () {
266284
-p
267285
');
268286

269-
Assert::exception(function () use ($cmd) {
270-
$cmd->parse(['-x']);
271-
}, Throwable::class, 'Unknown option -x.');
272-
273-
Assert::exception(function () use ($cmd) {
274-
$cmd->parse(['val']);
275-
}, Throwable::class, 'Unexpected parameter val.');
287+
Assert::exception(
288+
fn() => $cmd->parse(['-x']),
289+
Throwable::class,
290+
'Unknown option -x.',
291+
);
292+
293+
Assert::exception(
294+
fn() => $cmd->parse(['val']),
295+
Throwable::class,
296+
'Unexpected parameter val.',
297+
);
276298
});

0 commit comments

Comments
 (0)