3 namespace Drupal\Tests\Component\Utility;
5 use Drupal\Component\Utility\Environment;
6 use PHPUnit\Framework\TestCase;
9 * Test PHP Environment helper methods.
13 * @coversDefaultClass \Drupal\Component\Utility\Environment
15 class EnvironmentTest extends TestCase {
18 * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
20 * @dataProvider providerTestCheckMemoryLimit
21 * @covers ::checkMemoryLimit
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().
33 public function testCheckMemoryLimit($required, $custom_memory_limit, $expected) {
34 $actual = Environment::checkMemoryLimit($required, $custom_memory_limit);
35 $this->assertEquals($expected, $actual);
39 * Provides data for testCheckMemoryLimit().
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.
46 public function providerTestCheckMemoryLimit() {
47 $memory_limit = ini_get('memory_limit');
48 $twice_avail_memory = ($memory_limit * 2) . 'MB';
51 // Minimal amount of memory should be available.
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],