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/lib/MemoryInfoTest.php | |
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/lib/MemoryInfoTest.php')
-rw-r--r-- | tests/lib/MemoryInfoTest.php | 56 |
1 files changed, 40 insertions, 16 deletions
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); } } |