mirror of
https://github.com/danog/psalm.git
synced 2024-12-04 02:27:59 +01:00
4b31058234
This addresses https://github.com/vimeo/psalm/pull/6030#issuecomment-872611832 Previously PHP would allow to set memory limit to be below current memory usage, and the test changed in this PR abused that. As we actually don't need to test `ini_get()` value decoding was split into its own method, and we're testing that decoding instead.
55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Psalm\Tests\CommandFunctions;
|
|
|
|
use Psalm\Internal\CliUtils;
|
|
|
|
class GetMemoryLimitInBytesTest extends \Psalm\Tests\TestCase
|
|
{
|
|
/**
|
|
* @return array<int,array<string|int>>
|
|
*/
|
|
public function memoryLimitSettingProvider(): array
|
|
{
|
|
return [
|
|
// unlimited
|
|
[-1, -1],
|
|
// byte values
|
|
[1, 1],
|
|
[512, 512],
|
|
[2048, 2048],
|
|
// uppercase units
|
|
['1K', 1024],
|
|
['24K', 24576],
|
|
['1M', 1048576],
|
|
['24M', 25165824],
|
|
['1G', 1073741824],
|
|
['24G', 25769803776],
|
|
// lowercase units
|
|
['1k', 1024],
|
|
['24k', 24576],
|
|
['1m', 1048576],
|
|
['24m', 25165824],
|
|
['1g', 1073741824],
|
|
['24g', 25769803776],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider memoryLimitSettingProvider
|
|
*
|
|
* @param int|string $setting
|
|
* @param int|string $expectedBytes
|
|
*/
|
|
public function testGetMemoryLimitInBytes(
|
|
$setting,
|
|
$expectedBytes
|
|
): void {
|
|
$this->assertSame(
|
|
$expectedBytes,
|
|
CliUtils::convertMemoryLimitToBytes((string)$setting),
|
|
'Memory limit in bytes does not fit setting'
|
|
);
|
|
}
|
|
}
|