mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
12bd31f936
API Move environment / global / ini management into Environment class API Move getTempFolder into TempFolder class API Implement HTTPRequestBuilder / CLIRequestBuilder BUG Restore SS_ALLOWED_HOSTS check in original location API CoreKernel now requires $basePath to be passed in API Refactor installer.php to use application to bootstrap API move memstring conversion globals to Convert BUG Fix error in CoreKernel nesting not un-nesting itself properly.
99 lines
3.3 KiB
PHP
99 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace SilverStripe\Core\Tests;
|
|
|
|
use SilverStripe\Core\Environment;
|
|
use SilverStripe\Dev\SapphireTest;
|
|
|
|
class MemoryLimitTest extends SapphireTest
|
|
{
|
|
protected $origMemLimitMax;
|
|
protected $origTimeLimitMax;
|
|
protected $origMemLimit;
|
|
protected $origTimeLimit;
|
|
|
|
protected function setUp()
|
|
{
|
|
parent::setUp();
|
|
|
|
// see http://www.hardened-php.net/suhosin/configuration.html#suhosin.memory_limit
|
|
if (in_array('suhosin', get_loaded_extensions())) {
|
|
$this->markTestSkipped("This test cannot be run with suhosin installed");
|
|
} else {
|
|
$this->origMemLimit = ini_get('memory_limit');
|
|
$this->origTimeLimit = ini_get('max_execution_time');
|
|
$this->origMemLimitMax = Environment::getMemoryLimitMax();
|
|
$this->origTimeLimitMax = Environment::getTimeLimitMax();
|
|
Environment::setMemoryLimitMax(null);
|
|
Environment::setTimeLimitMax(null);
|
|
}
|
|
}
|
|
|
|
protected function tearDown()
|
|
{
|
|
if (!in_array('suhosin', get_loaded_extensions())) {
|
|
ini_set('memory_limit', $this->origMemLimit);
|
|
set_time_limit($this->origTimeLimit);
|
|
Environment::setMemoryLimitMax($this->origMemLimitMax);
|
|
Environment::setTimeLimitMax($this->origTimeLimitMax);
|
|
}
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function testIncreaseMemoryLimitTo()
|
|
{
|
|
ini_set('memory_limit', '64M');
|
|
|
|
// It can go up
|
|
Environment::increaseMemoryLimitTo('128M');
|
|
$this->assertEquals('128M', ini_get('memory_limit'));
|
|
|
|
// But not down
|
|
Environment::increaseMemoryLimitTo('64M');
|
|
$this->assertEquals('128M', ini_get('memory_limit'));
|
|
|
|
// Test the different kinds of syntaxes
|
|
Environment::increaseMemoryLimitTo(1024*1024*200);
|
|
$this->assertEquals(1024*1024*200, ini_get('memory_limit'));
|
|
|
|
Environment::increaseMemoryLimitTo('409600K');
|
|
$this->assertEquals('409600K', ini_get('memory_limit'));
|
|
|
|
Environment::increaseMemoryLimitTo('1G');
|
|
|
|
// If memory limit was left at 409600K, that means that the current testbox doesn't have
|
|
// 1G of memory available. That's okay; let's not report a failure for that.
|
|
if (ini_get('memory_limit') != '409600K') {
|
|
$this->assertEquals('1G', ini_get('memory_limit'));
|
|
}
|
|
|
|
// No argument means unlimited
|
|
Environment::increaseMemoryLimitTo();
|
|
$this->assertEquals(-1, ini_get('memory_limit'));
|
|
}
|
|
|
|
public function testIncreaseTimeLimitTo()
|
|
{
|
|
// Can't change time limit
|
|
if (!set_time_limit(6000)) {
|
|
$this->markTestSkipped("Cannot change time limit");
|
|
}
|
|
|
|
// It can go up
|
|
$this->assertTrue(Environment::increaseTimeLimitTo(7000));
|
|
$this->assertEquals(7000, ini_get('max_execution_time'));
|
|
|
|
// But not down
|
|
$this->assertTrue(Environment::increaseTimeLimitTo(5000));
|
|
$this->assertEquals(7000, ini_get('max_execution_time'));
|
|
|
|
// 0/nothing means infinity
|
|
$this->assertTrue(Environment::increaseTimeLimitTo());
|
|
$this->assertEquals(0, ini_get('max_execution_time'));
|
|
|
|
// Can't go down from there
|
|
$this->assertTrue(Environment::increaseTimeLimitTo(10000));
|
|
$this->assertEquals(0, ini_get('max_execution_time'));
|
|
}
|
|
}
|