EnvironmentTest.php 1.7 KB

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