You are here

class EnvironmentTest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php \Drupal\Tests\Component\Utility\EnvironmentTest

Test PHP Environment helper methods.

@group Utility

@coversDefaultClass \Drupal\Component\Utility\Environment

Hierarchy

  • class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of EnvironmentTest

File

core/tests/Drupal/Tests/Component/Utility/EnvironmentTest.php, line 20
Contains \Drupal\Tests\Component\Utility\EnvironmentTest.

Namespace

Drupal\Tests\Component\Utility
View source
class EnvironmentTest extends UnitTestCase {

  /**
   * Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
   *
   * @dataProvider providerTestCheckMemoryLimit
   * @covers ::checkMemoryLimit
   *
   * @param string $required
   *   The required memory argument for
   *   \Drupal\Component\Utility\Environment::checkMemoryLimit().
   * @param string $custom_memory_limit
   *   The custom memory limit argument for
   *   \Drupal\Component\Utility\Environment::checkMemoryLimit().
   * @param bool $expected
   *   The expected return value from
   *   \Drupal\Component\Utility\Environment::checkMemoryLimit().
   */
  public function testCheckMemoryLimit($required, $custom_memory_limit, $expected) {
    $actual = Environment::checkMemoryLimit($required, $custom_memory_limit);
    $this
      ->assertEquals($expected, $actual);
  }

  /**
   * Provides data for testCheckMemoryLimit().
   *
   * @return array
   *   An array of arrays, each containing the arguments for
   *   \Drupal\Component\Utility\Environment::checkMemoryLimit():
   *   required and memory_limit, and the expected return value.
   */
  public function providerTestCheckMemoryLimit() {
    $memory_limit = ini_get('memory_limit');
    $twice_avail_memory = $memory_limit * 2 . 'MB';
    return array(
      // Minimal amount of memory should be available.
      array(
        '30MB',
        NULL,
        TRUE,
      ),
      // Exceed a custom (unlimited) memory limit.
      array(
        $twice_avail_memory,
        -1,
        TRUE,
      ),
      // Exceed a custom memory limit.
      array(
        '30MB',
        '16MB',
        FALSE,
      ),
      // Available = required.
      array(
        '30MB',
        '30MB',
        TRUE,
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EnvironmentTest::providerTestCheckMemoryLimit public function Provides data for testCheckMemoryLimit().
EnvironmentTest::testCheckMemoryLimit public function Tests \Drupal\Component\Utility\Environment::checkMemoryLimit().
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
UnitTestCase::setUp protected function 259