@@ -39,8 +39,8 @@ public function testStringEstimation(): void
3939 $ longEstimate = $ this ->callEstimateJsonSize ($ longString );
4040
4141 // Should be string length + STRING_OVERHEAD (20)
42- $ this ->assertEquals (strlen ($ shortString ) + 20 , $ shortEstimate );
43- $ this ->assertEquals (strlen ($ longString ) + 20 , $ longEstimate );
42+ $ this ->assertEquals (strlen ($ shortString ) + JsonBufferPool:: STRING_OVERHEAD , $ shortEstimate );
43+ $ this ->assertEquals (strlen ($ longString ) + JsonBufferPool:: STRING_OVERHEAD , $ longEstimate );
4444
4545 // Longer strings should have larger estimates
4646 $ this ->assertGreaterThan ($ shortEstimate , $ longEstimate );
@@ -64,7 +64,7 @@ public function testArrayEstimationThresholds(): void
6464 $ xlargeEstimate = $ this ->callEstimateJsonSize ($ xlargeArray );
6565
6666 // Empty array should be smallest (2 bytes for [])
67- $ this ->assertEquals (2 , $ emptyEstimate );
67+ $ this ->assertEquals (JsonBufferPool:: EMPTY_ARRAY_SIZE , $ emptyEstimate );
6868
6969 // Each category should be larger than the previous
7070 $ this ->assertGreaterThan ($ emptyEstimate , $ smallEstimate );
@@ -73,10 +73,10 @@ public function testArrayEstimationThresholds(): void
7373 $ this ->assertGreaterThan ($ largeEstimate , $ xlargeEstimate );
7474
7575 // Verify expected sizes based on constants
76- $ this ->assertEquals (512 , $ smallEstimate ); // SMALL_ARRAY_SIZE
77- $ this ->assertEquals (2048 , $ mediumEstimate ); // MEDIUM_ARRAY_SIZE
78- $ this ->assertEquals (8192 , $ largeEstimate ); // LARGE_ARRAY_SIZE
79- $ this ->assertEquals (32768 , $ xlargeEstimate ); // XLARGE_ARRAY_SIZE
76+ $ this ->assertEquals (JsonBufferPool:: SMALL_ARRAY_SIZE , $ smallEstimate );
77+ $ this ->assertEquals (JsonBufferPool:: MEDIUM_ARRAY_SIZE , $ mediumEstimate );
78+ $ this ->assertEquals (JsonBufferPool:: LARGE_ARRAY_SIZE , $ largeEstimate );
79+ $ this ->assertEquals (JsonBufferPool:: XLARGE_ARRAY_SIZE , $ xlargeEstimate );
8080 }
8181
8282 /**
@@ -93,15 +93,21 @@ public function testObjectEstimation(): void
9393 $ largeEstimate = $ this ->callEstimateJsonSize ($ largeObject );
9494
9595 // Empty object should be base size (100)
96- $ this ->assertEquals (100 , $ emptyEstimate );
96+ $ this ->assertEquals (JsonBufferPool:: OBJECT_BASE_SIZE , $ emptyEstimate );
9797
9898 // Objects with properties should be larger
9999 $ this ->assertGreaterThan ($ emptyEstimate , $ smallEstimate );
100100 $ this ->assertGreaterThan ($ smallEstimate , $ largeEstimate );
101101
102- // Should follow formula: property_count * 50 + 100
103- $ this ->assertEquals (2 * 50 + 100 , $ smallEstimate ); // 2 properties
104- $ this ->assertEquals (10 * 50 + 100 , $ largeEstimate ); // 10 properties
102+ // Should follow formula: property_count * OBJECT_PROPERTY_OVERHEAD + OBJECT_BASE_SIZE
103+ $ this ->assertEquals (
104+ 2 * JsonBufferPool::OBJECT_PROPERTY_OVERHEAD + JsonBufferPool::OBJECT_BASE_SIZE ,
105+ $ smallEstimate
106+ ); // 2 properties
107+ $ this ->assertEquals (
108+ 10 * JsonBufferPool::OBJECT_PROPERTY_OVERHEAD + JsonBufferPool::OBJECT_BASE_SIZE ,
109+ $ largeEstimate
110+ ); // 10 properties
105111 }
106112
107113 /**
@@ -120,12 +126,12 @@ public function testPrimitiveEstimations(): void
120126 $ floatEstimate = $ this ->callEstimateJsonSize ($ float );
121127
122128 // Boolean and null should be same size (10)
123- $ this ->assertEquals (10 , $ booleanEstimate );
124- $ this ->assertEquals (10 , $ nullEstimate );
129+ $ this ->assertEquals (JsonBufferPool:: BOOLEAN_OR_NULL_SIZE , $ booleanEstimate );
130+ $ this ->assertEquals (JsonBufferPool:: BOOLEAN_OR_NULL_SIZE , $ nullEstimate );
125131
126132 // Numeric values should be same size (20)
127- $ this ->assertEquals (20 , $ integerEstimate );
128- $ this ->assertEquals (20 , $ floatEstimate );
133+ $ this ->assertEquals (JsonBufferPool:: NUMERIC_SIZE , $ integerEstimate );
134+ $ this ->assertEquals (JsonBufferPool:: NUMERIC_SIZE , $ floatEstimate );
129135 }
130136
131137 /**
@@ -139,7 +145,7 @@ public function testDefaultEstimation(): void
139145 fclose ($ resource );
140146
141147 // Should return default estimate (100)
142- $ this ->assertEquals (100 , $ estimate );
148+ $ this ->assertEquals (JsonBufferPool:: DEFAULT_ESTIMATE , $ estimate );
143149 }
144150
145151 /**
@@ -153,11 +159,11 @@ public function testOptimalCapacityCalculation(): void
153159 $ smallCapacity = JsonBufferPool::getOptimalCapacity ($ smallData );
154160 $ largeCapacity = JsonBufferPool::getOptimalCapacity ($ largeData );
155161
156- // Small data should fit in standard categories
162+ // Small data should fit in standard categories (1024, 4096, 16384, 65536)
157163 $ this ->assertContains ($ smallCapacity , [1024 , 4096 , 16384 , 65536 ]);
158164
159165 // Large data should get calculated capacity
160- $ this ->assertGreaterThanOrEqual (65536 , $ largeCapacity );
166+ $ this ->assertGreaterThanOrEqual (JsonBufferPool:: MIN_LARGE_BUFFER_SIZE , $ largeCapacity );
161167 $ this ->assertGreaterThan ($ smallCapacity , $ largeCapacity );
162168 }
163169
@@ -167,10 +173,10 @@ public function testOptimalCapacityCalculation(): void
167173 public function testConstantsAreReasonable (): void
168174 {
169175 // Test that size constants are in ascending order
170- $ this ->assertLessThan (512 , 2 ); // EMPTY < SMALL
171- $ this ->assertLessThan (2048 , 512 ); // SMALL < MEDIUM
172- $ this ->assertLessThan (8192 , 2048 ); // MEDIUM < LARGE
173- $ this ->assertLessThan (32768 , 8192 ); // LARGE < XLARGE
176+ $ this ->assertLessThan (JsonBufferPool:: SMALL_ARRAY_SIZE , JsonBufferPool:: EMPTY_ARRAY_SIZE ); // EMPTY < SMALL
177+ $ this ->assertLessThan (JsonBufferPool:: MEDIUM_ARRAY_SIZE , JsonBufferPool:: SMALL_ARRAY_SIZE ); // SMALL < MEDIUM
178+ $ this ->assertLessThan (JsonBufferPool:: LARGE_ARRAY_SIZE , JsonBufferPool:: MEDIUM_ARRAY_SIZE ); // MEDIUM < LARGE
179+ $ this ->assertLessThan (JsonBufferPool:: XLARGE_ARRAY_SIZE , JsonBufferPool:: LARGE_ARRAY_SIZE ); // LARGE < XLARGE
174180
175181 // Test threshold constants are in ascending order
176182 $ this ->assertLessThan (
@@ -183,9 +189,9 @@ public function testConstantsAreReasonable(): void
183189 ); // MEDIUM < LARGE threshold
184190
185191 // Test overhead constants are reasonable
186- $ this ->assertGreaterThan (0 , 20 ); // STRING_OVERHEAD > 0
187- $ this ->assertGreaterThan (0 , 50 ); // OBJECT_PROPERTY_OVERHEAD > 0
188- $ this ->assertGreaterThan (0 , 100 ); // OBJECT_BASE_SIZE > 0
192+ $ this ->assertGreaterThan (0 , JsonBufferPool:: STRING_OVERHEAD ); // STRING_OVERHEAD > 0
193+ $ this ->assertGreaterThan (0 , JsonBufferPool:: OBJECT_PROPERTY_OVERHEAD ); // OBJECT_PROPERTY_OVERHEAD > 0
194+ $ this ->assertGreaterThan (0 , JsonBufferPool:: OBJECT_BASE_SIZE ); // OBJECT_BASE_SIZE > 0
189195 }
190196
191197 /**
0 commit comments