Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\Component\Utility;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Component\Utility\Environment;
|
Chris@0
|
6 use PHPUnit\Framework\TestCase;
|
Chris@0
|
7
|
Chris@0
|
8 /**
|
Chris@0
|
9 * Test PHP Environment helper methods.
|
Chris@0
|
10 *
|
Chris@0
|
11 * @group Utility
|
Chris@0
|
12 *
|
Chris@0
|
13 * @coversDefaultClass \Drupal\Component\Utility\Environment
|
Chris@0
|
14 */
|
Chris@0
|
15 class EnvironmentTest extends TestCase {
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
|
Chris@0
|
19 *
|
Chris@0
|
20 * @dataProvider providerTestCheckMemoryLimit
|
Chris@0
|
21 * @covers ::checkMemoryLimit
|
Chris@0
|
22 *
|
Chris@0
|
23 * @param string $required
|
Chris@0
|
24 * The required memory argument for
|
Chris@0
|
25 * \Drupal\Component\Utility\Environment::checkMemoryLimit().
|
Chris@0
|
26 * @param string $custom_memory_limit
|
Chris@0
|
27 * The custom memory limit argument for
|
Chris@0
|
28 * \Drupal\Component\Utility\Environment::checkMemoryLimit().
|
Chris@0
|
29 * @param bool $expected
|
Chris@0
|
30 * The expected return value from
|
Chris@0
|
31 * \Drupal\Component\Utility\Environment::checkMemoryLimit().
|
Chris@0
|
32 */
|
Chris@0
|
33 public function testCheckMemoryLimit($required, $custom_memory_limit, $expected) {
|
Chris@0
|
34 $actual = Environment::checkMemoryLimit($required, $custom_memory_limit);
|
Chris@0
|
35 $this->assertEquals($expected, $actual);
|
Chris@0
|
36 }
|
Chris@0
|
37
|
Chris@0
|
38 /**
|
Chris@0
|
39 * Provides data for testCheckMemoryLimit().
|
Chris@0
|
40 *
|
Chris@0
|
41 * @return array
|
Chris@0
|
42 * An array of arrays, each containing the arguments for
|
Chris@0
|
43 * \Drupal\Component\Utility\Environment::checkMemoryLimit():
|
Chris@0
|
44 * required and memory_limit, and the expected return value.
|
Chris@0
|
45 */
|
Chris@0
|
46 public function providerTestCheckMemoryLimit() {
|
Chris@0
|
47 return [
|
Chris@0
|
48 // Minimal amount of memory should be available.
|
Chris@0
|
49 ['30MB', NULL, TRUE],
|
Chris@17
|
50 // Test an unlimited memory limit.
|
Chris@17
|
51 ['9999999999YB', -1, TRUE],
|
Chris@0
|
52 // Exceed a custom memory limit.
|
Chris@0
|
53 ['30MB', '16MB', FALSE],
|
Chris@0
|
54 // Available = required.
|
Chris@0
|
55 ['30MB', '30MB', TRUE],
|
Chris@0
|
56 ];
|
Chris@0
|
57 }
|
Chris@0
|
58
|
Chris@0
|
59 }
|