1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 02:27:59 +01:00
psalm/tests/CommandFunctions/GetMemoryLimitInBytesTest.php
Bruce Weirdan 448534fd7c
Cli command classes (#5858)
* Move psalm entry-point to a Cli command class

* Moved psalter to the CLI command class

* Moved psalm-language-server to the CLI command class

* Moved psalm-refactor to the CLI command class

* Moved psalm_plugin to the CLI command class

* Use CLI commands directly and deprecate trampolines

* Require CLI commands directly and don't use trampolines

* Announce isAbsolutePath() removal

* Deprecate \Psalm\requireAutoloaders() function

* Deprecate \Psalm\getVendorDir() function

* Deprecate Psalm\getArguments() function

* Deprecate \Psalm\getPathsToCheck() function

* Deprecate \Psalm\getPsalmHelpText() function

* Deprecate \Psalm\initialiseConfig() function

* Deprecate Psalm\update_config_file() function

* Deprecate \Psalm\get_path_to_config() function

* Deprecate Psalm\getMemoryLimitInBytes() function

* CS fix

* Untangle Psalm entrypoint

* Untangle Psalter entrypoint

* Drop command_functions.php references

* Adjust phar build
2021-05-31 22:23:54 -04:00

75 lines
1.7 KiB
PHP

<?php
namespace Psalm\Tests\CommandFunctions;
use Psalm\Internal\CliUtils;
use function ini_set;
use function ini_get;
/**
* testcase for src/command_functions.php
*/
class GetMemoryLimitInBytesTest extends \Psalm\Tests\TestCase
{
/**
* @var string
*/
private $previousLimit;
public function setUp(): void
{
$this->previousLimit = (string)ini_get('memory_limit');
parent::setUp();
}
/**
* @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 {
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();
}
}