Skip to content

Commit 47bf50d

Browse files
committed
Helpers::formatArgs() checks for insufficient number of placeholders (BC break)
1 parent b0482ce commit 47bf50d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ public static function formatArgs($statement, array $args)
194194
}
195195
$a = strpos($statement, '?', $a);
196196
}
197+
if ($args) {
198+
throw new Nette\InvalidArgumentException('Insufficient number of placeholders.');
199+
}
197200
return $statement;
198201
}
199202

tests/PhpGenerator/Helpers.format.phpt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ require __DIR__ . '/../bootstrap.php';
1414

1515

1616
Assert::same('func', Helpers::format('func'));
17-
Assert::same('func(1)', Helpers::format('func(?)', 1, 2));
18-
19-
Assert::same('func', Helpers::formatArgs('func', [1, 2]));
20-
Assert::same('func(1)', Helpers::formatArgs('func(?)', [1, 2]));
17+
Assert::same('func(1)', Helpers::format('func(?)', 1));
18+
Assert::same('func', Helpers::formatArgs('func', []));
19+
Assert::same('func(1)', Helpers::formatArgs('func(?)', [1]));
2120
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
2221
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]]));
2322
Assert::same(
@@ -29,6 +28,10 @@ Assert::exception(function () {
2928
Helpers::formatArgs('func(?*)', [1, 2]);
3029
}, Nette\InvalidArgumentException::class, 'Argument must be an array.');
3130

31+
Assert::exception(function () {
32+
Helpers::format('func(?)', 1, 2);
33+
}, Nette\InvalidArgumentException::class, 'Insufficient number of placeholders.');
34+
3235
Assert::exception(function () {
3336
Helpers::formatArgs('func(?, ?, ?)', [1, 2]);
3437
}, Nette\InvalidArgumentException::class, 'Insufficient number of arguments.');

0 commit comments

Comments
 (0)