2020-02-24 21:24:42 +01:00
|
|
|
<?php
|
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;
|
|
|
|
|
2020-02-24 22:23:16 +01:00
|
|
|
use function ini_get;
|
2021-06-08 04:55:21 +02:00
|
|
|
use function ini_set;
|
2020-02-24 21:24:42 +01:00
|
|
|
|
2020-08-08 05:22:30 +02:00
|
|
|
/**
|
|
|
|
* testcase for src/command_functions.php
|
|
|
|
*/
|
2020-02-24 21:24:42 +01:00
|
|
|
class GetMemoryLimitInBytesTest extends \Psalm\Tests\TestCase
|
|
|
|
{
|
2020-02-24 22:23:16 +01:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $previousLimit;
|
|
|
|
|
2020-02-24 22:18:46 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
2020-02-24 22:23:16 +01:00
|
|
|
$this->previousLimit = (string)ini_get('memory_limit');
|
2020-02-24 22:18:46 +01:00
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
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],
|
|
|
|
[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
|
|
|
|
*
|
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 {
|
2020-02-24 21:47:05 +01:00
|
|
|
ini_set('memory_limit', (string)$setting);
|
2021-06-01 04:23:54 +02:00
|
|
|
$this->assertSame($expectedBytes, CliUtils::getMemoryLimitInBytes(), 'Memory limit in bytes does not fit setting');
|
2020-02-24 21:24:42 +01:00
|
|
|
}
|
2020-02-24 22:23:16 +01:00
|
|
|
|
|
|
|
public function tearDown(): void
|
|
|
|
{
|
|
|
|
ini_set('memory_limit', $this->previousLimit);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2020-02-24 21:24:42 +01:00
|
|
|
}
|