diff options
author | Michael Weimann <mail@michael-weimann.eu> | 2018-08-04 21:54:00 +0200 |
---|---|---|
committer | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2018-08-20 15:24:10 +0200 |
commit | 7aed47f776b8175e7947bb2b202b96a3f236bdce (patch) | |
tree | 11e0a57e9ccc47389fa9d235f0abc20f7190cad0 /tests | |
parent | c164409ee7f921a96f95e1fe95d86fe07a98963e (diff) | |
download | nextcloud-server-7aed47f776b8175e7947bb2b202b96a3f236bdce.tar.gz nextcloud-server-7aed47f776b8175e7947bb2b202b96a3f236bdce.zip |
Adds tests for the memory checks
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/CheckSetupControllerTest.php | 48 | ||||
-rw-r--r-- | tests/lib/MemoryInfoTest.php | 56 |
2 files changed, 44 insertions, 60 deletions
diff --git a/tests/Settings/Controller/CheckSetupControllerTest.php b/tests/Settings/Controller/CheckSetupControllerTest.php index 617394682e7..a7689eed801 100644 --- a/tests/Settings/Controller/CheckSetupControllerTest.php +++ b/tests/Settings/Controller/CheckSetupControllerTest.php @@ -78,13 +78,6 @@ class CheckSetupControllerTest extends TestCase { /** @var MemoryInfo|MockObject */ private $memoryInfo; - /** - * Backup of the "memory_limit" ini value before tests. - * - * @var string - */ - private $memoryLimitIniValueBeforeTest; - public function setUp() { parent::setUp(); @@ -115,7 +108,7 @@ class CheckSetupControllerTest extends TestCase { $this->lockingProvider = $this->getMockBuilder(ILockingProvider::class)->getMock(); $this->dateTimeFormatter = $this->getMockBuilder(IDateTimeFormatter::class)->getMock(); $this->memoryInfo = $this->getMockBuilder(MemoryInfo::class) - ->setMethods(['getMemoryLimit',]) + ->setMethods(['isMemoryLimitSufficient',]) ->getMock(); $this->checkSetupController = $this->getMockBuilder('\OC\Settings\Controller\CheckSetupController') ->setConstructorArgs([ @@ -440,8 +433,8 @@ class CheckSetupControllerTest extends TestCase { ->method('hasPassedCheck') ->willReturn(true); $this->memoryInfo - ->method('getMemoryLimit') - ->willReturn(512 * 1024 * 1024); + ->method('isMemoryLimitSufficient') + ->willReturn(true); $expected = new DataResponse( [ @@ -483,7 +476,7 @@ class CheckSetupControllerTest extends TestCase { 'missingIndexes' => [], 'isPhpMailerUsed' => false, 'mailSettingsDocumentation' => 'https://server/index.php/settings/admin', - 'isTheMemoryLimitHighEnough' => true, + 'isMemoryLimitSufficient' => true, ] ); $this->assertEquals($expected, $this->checkSetupController->check()); @@ -1180,37 +1173,4 @@ Array ); $this->assertEquals($expected, $this->checkSetupController->getFailedIntegrityCheckFiles()); } - - /** - * This function returns test values for the memory limit check. - * 1. the memory limit - * 2. the expected check value - * - * @return array - */ - public function getMemoryLimitTestData(): array { - return [ - 'unlimited' => [-1, true,], - '512M' => [512 * 1024 * 1024, true,], - '1G' => [1024 * 1024 * 1024, true,], - '64M' => [64 * 1024 * 1024, false,], - ]; - } - - /** - * Tests that if the memory limit is high enough, there is no message. - * - * @param string $memoryLimit The memory limit reported by MemoryInfo. - * @param bool $expected The expected memory check return value. - * @dataProvider getMemoryLimitTestData - */ - public function testMemoryLimit(string $memoryLimit, bool $expected) { - $this->memoryInfo - ->method('getMemoryLimit') - ->willReturn($memoryLimit); - $this->assertSame( - $expected, - $this->invokePrivate($this->checkSetupController, 'isTheMemoryLimitHighEnough') - ); - } } diff --git a/tests/lib/MemoryInfoTest.php b/tests/lib/MemoryInfoTest.php index 9cd4fd56038..057d3091b2c 100644 --- a/tests/lib/MemoryInfoTest.php +++ b/tests/lib/MemoryInfoTest.php @@ -3,17 +3,13 @@ namespace Test; use OC\MemoryInfo; +use PHPUnit\Framework\MockObject\MockObject; /** * This class provides tests for the MemoryInfo class. */ class MemoryInfoTest extends TestCase { /** - * @var MemoryInfo - */ - private $memoryInfo; - - /** * The "memory_limit" value before tests. * * @var string @@ -35,15 +31,6 @@ class MemoryInfoTest extends TestCase { } /** - * Setups a MemoryInfo instance for tests. - * - * @before - */ - public function setupMemoryInfo() { - $this->memoryInfo = new MemoryInfo(); - } - - /** * Provides test data. * * @return array @@ -66,8 +53,45 @@ class MemoryInfoTest extends TestCase { * @param int $expected The expected detected memory limit. * @dataProvider getMemoryLimitTestData */ - public function testMemoryLimit($iniValue, $expected) { + public function testMemoryLimit($iniValue, int $expected) { ini_set('memory_limit', $iniValue); - self::assertEquals($expected, $this->memoryInfo->getMemoryLimit()); + $memoryInfo = new MemoryInfo(); + self::assertEquals($expected, $memoryInfo->getMemoryLimit()); + } + + /** + * Provides sufficient memory limit test data. + * + * @return array + */ + public function getSufficientMemoryTestData(): array { + return [ + 'unlimited' => [-1, true,], + '512M' => [512 * 1024 * 1024, true,], + '1G' => [1024 * 1024 * 1024, true,], + '256M' => [256 * 1024 * 1024, false,], + ]; + } + + /** + * Tests that isMemoryLimitSufficient returns the correct values. + * + * @param int $memoryLimit The memory limit + * @param bool $expected If the memory limit is sufficient. + * @dataProvider getSufficientMemoryTestData + * @return void + */ + public function testIsMemoryLimitSufficient(int $memoryLimit, bool $expected) { + /* @var MemoryInfo|MockObject $memoryInfo */ + $memoryInfo = $this->getMockBuilder(MemoryInfo::class) + ->setMethods(['getMemoryLimit',]) + ->getMock(); + + $memoryInfo + ->method('getMemoryLimit') + ->willReturn($memoryLimit); + + $isMemoryLimitSufficient = $memoryInfo->isMemoryLimitSufficient(); + self::assertEquals($expected, $isMemoryLimitSufficient); } } |