diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index a8bfa216efd..24f7778460d 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -589,7 +589,12 @@ public static function getPathToConfig(array $options): ?string */ public static function getMemoryLimitInBytes(): int { - $limit = ini_get('memory_limit'); + return self::convertMemoryLimitToBytes(ini_get('memory_limit')); + } + + /** @psalm-pure */ + public static function convertMemoryLimitToBytes(string $limit): int + { // for unlimited = -1 if ($limit < 0) { return -1; diff --git a/tests/CommandFunctions/GetMemoryLimitInBytesTest.php b/tests/CommandFunctions/GetMemoryLimitInBytesTest.php index 006fc679bdd..70ceb7dcb9e 100644 --- a/tests/CommandFunctions/GetMemoryLimitInBytesTest.php +++ b/tests/CommandFunctions/GetMemoryLimitInBytesTest.php @@ -1,27 +1,11 @@ previousLimit = (string)ini_get('memory_limit'); - parent::setUp(); - } - /** * @return array> */ @@ -56,19 +40,15 @@ public function memoryLimitSettingProvider(): array * * @param int|string $setting * @param int|string $expectedBytes - * */ public function testGetMemoryLimitInBytes( $setting, $expectedBytes ): void { - ini_set('memory_limit', (string)$setting); - $this->assertSame($expectedBytes, CliUtils::getMemoryLimitInBytes(), 'Memory limit in bytes does not fit setting'); - } - - public function tearDown(): void - { - ini_set('memory_limit', $this->previousLimit); - parent::tearDown(); + $this->assertSame( + $expectedBytes, + CliUtils::convertMemoryLimitToBytes((string)$setting), + 'Memory limit in bytes does not fit setting' + ); } }