Skip to content

Commit 064af89

Browse files
committed
refactor(tests): atualizar mensagens de exceção para validação de tipo em JsonBufferPool
1 parent 933cd39 commit 064af89

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/Json/Pool/JsonBufferPool.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,14 @@ private static function validateConfiguration(array $config): void
281281
{
282282
// Validate 'max_pool_size'
283283
if (isset($config['max_pool_size'])) {
284-
if (!is_int($config['max_pool_size']) || $config['max_pool_size'] <= 0) {
284+
if (!is_int($config['max_pool_size'])) {
285285
throw new \InvalidArgumentException(
286-
"'max_pool_size' must be a positive integer, got: " . gettype($config['max_pool_size'])
286+
"'max_pool_size' must be an integer, got: " . gettype($config['max_pool_size'])
287287
);
288288
}
289+
if ($config['max_pool_size'] <= 0) {
290+
throw new \InvalidArgumentException("'max_pool_size' must be a positive integer");
291+
}
289292
if ($config['max_pool_size'] > 1000) {
290293
throw new \InvalidArgumentException(
291294
"'max_pool_size' cannot exceed 1000 for memory safety, got: {$config['max_pool_size']}"
@@ -295,11 +298,14 @@ private static function validateConfiguration(array $config): void
295298

296299
// Validate 'default_capacity'
297300
if (isset($config['default_capacity'])) {
298-
if (!is_int($config['default_capacity']) || $config['default_capacity'] <= 0) {
301+
if (!is_int($config['default_capacity'])) {
299302
throw new \InvalidArgumentException(
300-
"'default_capacity' must be a positive integer, got: " . gettype($config['default_capacity'])
303+
"'default_capacity' must be an integer, got: " . gettype($config['default_capacity'])
301304
);
302305
}
306+
if ($config['default_capacity'] <= 0) {
307+
throw new \InvalidArgumentException("'default_capacity' must be a positive integer");
308+
}
303309
if ($config['default_capacity'] > 1024 * 1024) { // 1MB limit
304310
throw new \InvalidArgumentException(
305311
"'default_capacity' cannot exceed 1MB (1048576 bytes), got: {$config['default_capacity']}"
@@ -324,9 +330,14 @@ private static function validateConfiguration(array $config): void
324330
throw new \InvalidArgumentException("Size category names must be non-empty strings");
325331
}
326332

327-
if (!is_int($capacity) || $capacity <= 0) {
333+
if (!is_int($capacity)) {
334+
throw new \InvalidArgumentException(
335+
"Size category '{$name}' must have an integer capacity, got: " . gettype($capacity)
336+
);
337+
}
338+
if ($capacity <= 0) {
328339
throw new \InvalidArgumentException(
329-
"Size category '{$name}' must have a positive integer capacity, got: " . gettype($capacity)
340+
"Size category '{$name}' must have a positive integer capacity"
330341
);
331342
}
332343

tests/Json/Pool/JsonBufferPoolConfigValidationTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testMaxPoolSizeZeroInvalid(): void
6969
public function testMaxPoolSizeTypeValidation(): void
7070
{
7171
$this->expectException(InvalidArgumentException::class);
72-
$this->expectExceptionMessage("'max_pool_size' must be a positive integer, got: string");
72+
$this->expectExceptionMessage("'max_pool_size' must be an integer, got: string");
7373
JsonBufferPool::configure(['max_pool_size' => '100']);
7474
}
7575

@@ -93,7 +93,7 @@ public function testDefaultCapacityValidation(): void
9393
public function testDefaultCapacityTypeValidation(): void
9494
{
9595
$this->expectException(InvalidArgumentException::class);
96-
$this->expectExceptionMessage("'default_capacity' must be a positive integer, got: double");
96+
$this->expectExceptionMessage("'default_capacity' must be an integer, got: double");
9797
JsonBufferPool::configure(['default_capacity' => 4096.5]);
9898
}
9999

@@ -150,7 +150,7 @@ public function testSizeCategoriesEmptyNameInvalid(): void
150150
public function testSizeCategoriesCapacityValidation(): void
151151
{
152152
$this->expectException(InvalidArgumentException::class);
153-
$this->expectExceptionMessage("Size category 'small' must have a positive integer capacity, got: string");
153+
$this->expectExceptionMessage("Size category 'small' must have an integer capacity, got: string");
154154
JsonBufferPool::configure(
155155
[
156156
'size_categories' => [

0 commit comments

Comments
 (0)