2020-02-24 21:24:42 +01:00
|
|
|
<?php
|
2021-07-02 01:59:43 +02:00
|
|
|
|
2020-08-08 05:22:30 +02:00
|
|
|
namespace Psalm\Tests\CommandFunctions;
|
2020-02-24 21:24:42 +01:00
|
|
|
|
2021-06-01 04:23:54 +02:00
|
|
|
use Psalm\Internal\CliUtils;
|
2021-12-03 20:11:20 +01:00
|
|
|
use Psalm\Tests\TestCase;
|
2021-06-01 04:23:54 +02:00
|
|
|
|
2021-12-03 20:11:20 +01:00
|
|
|
class GetMemoryLimitInBytesTest extends TestCase
|
2020-02-24 21:24:42 +01:00
|
|
|
{
|
2020-02-24 21:47:05 +01:00
|
|
|
/**
|
|
|
|
* @return array<int,array<string|int>>
|
|
|
|
*/
|
|
|
|
public function memoryLimitSettingProvider(): array
|
2020-02-24 21:24:42 +01:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
// unlimited
|
|
|
|
[-1, -1],
|
|
|
|
// byte values
|
|
|
|
[1, 1],
|
|
|
|
[512, 512],
|
2022-01-05 00:00:05 +01:00
|
|
|
[2_048, 2_048],
|
2020-02-24 21:24:42 +01:00
|
|
|
// uppercase units
|
2022-01-05 00:00:05 +01:00
|
|
|
['1K', 1_024],
|
|
|
|
['24K', 24_576],
|
|
|
|
['1M', 1_048_576],
|
|
|
|
['24M', 25_165_824],
|
|
|
|
['1G', 1_073_741_824],
|
|
|
|
['24G', 25_769_803_776],
|
2020-02-24 21:24:42 +01:00
|
|
|
// lowercase units
|
2022-01-05 00:00:05 +01:00
|
|
|
['1k', 1_024],
|
|
|
|
['24k', 24_576],
|
|
|
|
['1m', 1_048_576],
|
|
|
|
['24m', 25_165_824],
|
|
|
|
['1g', 1_073_741_824],
|
|
|
|
['24g', 25_769_803_776],
|
2020-02-24 21:24:42 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider memoryLimitSettingProvider
|
|
|
|
*
|
2020-02-24 21:47:05 +01:00
|
|
|
* @param int|string $setting
|
|
|
|
* @param int|string $expectedBytes
|
2020-02-24 21:24:42 +01:00
|
|
|
*/
|
|
|
|
public function testGetMemoryLimitInBytes(
|
|
|
|
$setting,
|
|
|
|
$expectedBytes
|
2020-09-12 17:24:05 +02:00
|
|
|
): void {
|
2021-07-02 01:59:43 +02:00
|
|
|
$this->assertSame(
|
|
|
|
$expectedBytes,
|
|
|
|
CliUtils::convertMemoryLimitToBytes((string)$setting),
|
|
|
|
'Memory limit in bytes does not fit setting'
|
|
|
|
);
|
2020-02-24 22:23:16 +01:00
|
|
|
}
|
2020-02-24 21:24:42 +01:00
|
|
|
}
|