Mercurial > hg > isophonics-drupal-site
comparison core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\Component\Utility; | |
4 | |
5 use Drupal\Component\Utility\Environment; | |
6 use PHPUnit\Framework\TestCase; | |
7 | |
8 /** | |
9 * Test PHP Environment helper methods. | |
10 * | |
11 * @group Utility | |
12 * | |
13 * @coversDefaultClass \Drupal\Component\Utility\Environment | |
14 */ | |
15 class EnvironmentTest extends TestCase { | |
16 | |
17 /** | |
18 * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit(). | |
19 * | |
20 * @dataProvider providerTestCheckMemoryLimit | |
21 * @covers ::checkMemoryLimit | |
22 * | |
23 * @param string $required | |
24 * The required memory argument for | |
25 * \Drupal\Component\Utility\Environment::checkMemoryLimit(). | |
26 * @param string $custom_memory_limit | |
27 * The custom memory limit argument for | |
28 * \Drupal\Component\Utility\Environment::checkMemoryLimit(). | |
29 * @param bool $expected | |
30 * The expected return value from | |
31 * \Drupal\Component\Utility\Environment::checkMemoryLimit(). | |
32 */ | |
33 public function testCheckMemoryLimit($required, $custom_memory_limit, $expected) { | |
34 $actual = Environment::checkMemoryLimit($required, $custom_memory_limit); | |
35 $this->assertEquals($expected, $actual); | |
36 } | |
37 | |
38 /** | |
39 * Provides data for testCheckMemoryLimit(). | |
40 * | |
41 * @return array | |
42 * An array of arrays, each containing the arguments for | |
43 * \Drupal\Component\Utility\Environment::checkMemoryLimit(): | |
44 * required and memory_limit, and the expected return value. | |
45 */ | |
46 public function providerTestCheckMemoryLimit() { | |
47 $memory_limit = ini_get('memory_limit'); | |
48 $twice_avail_memory = ($memory_limit * 2) . 'MB'; | |
49 | |
50 return [ | |
51 // Minimal amount of memory should be available. | |
52 ['30MB', NULL, TRUE], | |
53 // Exceed a custom (unlimited) memory limit. | |
54 [$twice_avail_memory, -1, TRUE], | |
55 // Exceed a custom memory limit. | |
56 ['30MB', '16MB', FALSE], | |
57 // Available = required. | |
58 ['30MB', '30MB', TRUE], | |
59 ]; | |
60 } | |
61 | |
62 } |