1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00
psalm/tests/command_functions/GetMemoryLimitInBytesTest.php

73 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace Psalm\Tests\Functions;
use function getMemoryLimitInBytes;
2020-02-24 21:55:07 +01:00
use function ini_set;
use function ini_get;
class GetMemoryLimitInBytesTest extends \Psalm\Tests\TestCase
{
/**
* @var string
*/
private $previousLimit;
public function setUp(): void
{
require_once 'src/command_functions.php';
$this->previousLimit = (string)ini_get('memory_limit');
parent::setUp();
}
2020-02-24 21:47:05 +01:00
/**
* @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
*
2020-02-24 21:47:05 +01:00
* @param int|string $setting
* @param int|string $expectedBytes
*
* @return void
*/
public function testGetMemoryLimitInBytes(
$setting,
$expectedBytes
) {
2020-02-24 21:47:05 +01:00
ini_set('memory_limit', (string)$setting);
$this->assertSame($expectedBytes, getMemoryLimitInBytes(), 'Memory limit in bytes does not fit setting');
}
public function tearDown(): void
{
ini_set('memory_limit', $this->previousLimit);
parent::tearDown();
}
}