You are here

protected function SizeUnitTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/src/Tests/Common/SizeUnitTest.php \Drupal\system\Tests\Common\SizeUnitTest::setUp()

Performs setup tasks before each individual test method is run.

Overrides KernelTestBase::setUp

File

core/modules/system/src/Tests/Common/SizeUnitTest.php, line 23
Contains \Drupal\system\Tests\Common\SizeUnitTest.

Class

SizeUnitTest
Parse a predefined amount of bytes and compare the output with the expected value.

Namespace

Drupal\system\Tests\Common

Code

protected function setUp() {
  parent::setUp();
  $kb = Bytes::KILOBYTE;
  $this->exactTestCases = array(
    '1 byte' => 1,
    '1 KB' => $kb,
    '1 MB' => $kb * $kb,
    '1 GB' => $kb * $kb * $kb,
    '1 TB' => $kb * $kb * $kb * $kb,
    '1 PB' => $kb * $kb * $kb * $kb * $kb,
    '1 EB' => $kb * $kb * $kb * $kb * $kb * $kb,
    '1 ZB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb,
    '1 YB' => $kb * $kb * $kb * $kb * $kb * $kb * $kb * $kb,
  );
  $this->roundedTestCases = array(
    '2 bytes' => 2,
    '1 MB' => $kb * $kb - 1,
    // rounded to 1 MB (not 1000 or 1024 kilobyte!)
    round(3623651 / $this->exactTestCases['1 MB'], 2) . ' MB' => 3623651,
    // megabytes
    round(67234178751368124 / $this->exactTestCases['1 PB'], 2) . ' PB' => 67234178751368124,
    // petabytes
    round(2.3534682382112583E+26 / $this->exactTestCases['1 YB'], 2) . ' YB' => 2.3534682382112583E+26,
  );
}