diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d405e..4b061a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,8 @@ - Bug #191: Refactor test imports for consistency and add support files (@terabytesoftw) - Bug #192: Add copyright and license information to `MockerExtension::class` and refactor `tests/support/bootstrap.php` (@terabytesoftw) - Bug #193: Update `.editorconfig` and `.gitignore` for improved consistency and clarity (@terabytesoftw) -- Bug #194: Update symplify/easy-coding-standard requirement from `^12.5` to `^13.0` (@dependabot) +- Dep #194: Update symplify/easy-coding-standard requirement from `^12.5` to `^13.0` (@dependabot) +- Bug #195: Add test for memory usage at `90%` threshold in `ApplicationMemoryTest` class (@terabytesoftw) ## 0.1.1 October 6, 2025 diff --git a/tests/http/stateless/ApplicationMemoryTest.php b/tests/http/stateless/ApplicationMemoryTest.php index 5b49ac7..81a7bcb 100644 --- a/tests/http/stateless/ApplicationMemoryTest.php +++ b/tests/http/stateless/ApplicationMemoryTest.php @@ -45,11 +45,8 @@ final class ApplicationMemoryTest extends TestCase * @throws InvalidConfigException if the configuration is invalid or incomplete. */ #[DataProviderExternal(StatelessApplicationProvider::class, 'memoryThreshold')] - public function testCleanBehaviorWithDifferentMemoryLimits( - string $memoryLimit, - bool $shouldTriggerSpecialTest, - string $assertionMessage, - ): void { + public function testCleanBehaviorWithDifferentMemoryLimits(string $memoryLimit, string $assertionMessage): void + { $originalLimit = ini_get('memory_limit'); ini_set('memory_limit', $memoryLimit); @@ -58,21 +55,30 @@ public function testCleanBehaviorWithDifferentMemoryLimits( $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals()); - if ($shouldTriggerSpecialTest === false) { - self::assertFalse($app->clean(), $assertionMessage); - } + self::assertFalse($app->clean(), $assertionMessage); - if ($shouldTriggerSpecialTest === true) { - $currentUsage = memory_get_usage(true); + ini_set('memory_limit', $originalLimit); + } - $artificialLimit = (int) ($currentUsage / 0.9); + /** + * @throws InvalidConfigException if the configuration is invalid or incomplete. + */ + public function testCleanReturnsTrueWhenMemoryUsageIsExactlyPercentThreshold(): void + { + $app = $this->statelessApplication(); - $app->setMemoryLimit($artificialLimit); + $app->handle(FactoryHelper::createServerRequestCreator()->createFromGlobals()); - self::assertTrue($app->clean(), $assertionMessage); - } + $currentUsage = memory_get_usage(true); - ini_set('memory_limit', $originalLimit); + $exactLimit = (int) ($currentUsage / 0.9); + + $app->setMemoryLimit($exactLimit); + + self::assertTrue( + $app->clean(), + "Should return 'true' when memory usage is exactly at '90%' threshold (boundary condition).", + ); } /** diff --git a/tests/provider/StatelessApplicationProvider.php b/tests/provider/StatelessApplicationProvider.php index 6fa0c1d..84fb184 100644 --- a/tests/provider/StatelessApplicationProvider.php +++ b/tests/provider/StatelessApplicationProvider.php @@ -443,36 +443,26 @@ public static function memoryLimitPositive(): array * This provider supplies test cases for validating the logic that determines whether memory cleanup should be * triggered based on current memory usage and configured memory limits. * - * Each test case includes the memory limit string, the expected boolean result indicating whether cleanup should - * occur, and an assertion message describing the expected outcome. + * Each test case includes the memory limit string and an assertion message describing the expected outcome. * - * @return array test data with memory limit, expected cleanup result, and assertion message. + * @return array test data with memory limit and assertion message. * - * @phpstan-return array + * @phpstan-return array */ public static function memoryThreshold(): array { return [ 'low usage - should not clean' => [ '1G', - false, - "'clean()' should return 'false' when memory usage is below '90%' threshold with '1G' limit.", + "Should return 'false' when memory usage is below '90%' threshold with '1G' limit.", ], 'moderate usage - should not clean' => [ '512M', - false, - "'clean()' should return 'false' when memory usage is below '90%' threshold with '512M' limit.", + "Should return 'false' when memory usage is below '90%' threshold with '512M' limit.", ], 'threshold calculation - 100M' => [ '100M', - false, - "'clean()' should return 'false' with '100M' limit and verify correct '90%' threshold calculation.", - ], - 'high memory setup - 2G' => [ - '2G', - true, - "'clean()' should return 'true' when memory usage equals the calculated '90%' threshold " . - '(using adjusted limit).', + "Should return 'false' with '100M' limit and verify correct '90%' threshold calculation.", ], ]; }