You are here

protected function MigrateExecutableMemoryExceededTest::runMemoryExceededTest in Drupal 8

Runs the actual test.

Parameters

string $message: The second message to assert.

bool $memory_exceeded: Whether to test the memory exceeded case.

int|null $memory_usage_first: (optional) The first memory usage value. Defaults to NULL.

int|null $memory_usage_second: (optional) The fake amount of memory usage reported after memory reclaim. Defaults to NULL.

int|null $memory_limit: (optional) The memory limit. Defaults to NULL.

3 calls to MigrateExecutableMemoryExceededTest::runMemoryExceededTest()
MigrateExecutableMemoryExceededTest::testMemoryExceededClearedEnough in core/modules/migrate/tests/src/Unit/MigrateExecutableMemoryExceededTest.php
Tests memoryExceeded method when enough is cleared.
MigrateExecutableMemoryExceededTest::testMemoryExceededNewBatch in core/modules/migrate/tests/src/Unit/MigrateExecutableMemoryExceededTest.php
Tests memoryExceeded method when a new batch is needed.
MigrateExecutableMemoryExceededTest::testMemoryNotExceeded in core/modules/migrate/tests/src/Unit/MigrateExecutableMemoryExceededTest.php
Tests memoryExceeded when memory usage is not exceeded.

File

core/modules/migrate/tests/src/Unit/MigrateExecutableMemoryExceededTest.php, line 76

Class

MigrateExecutableMemoryExceededTest
Tests the \Drupal\migrate\MigrateExecutable::memoryExceeded() method.

Namespace

Drupal\Tests\migrate\Unit

Code

protected function runMemoryExceededTest($message, $memory_exceeded, $memory_usage_first = NULL, $memory_usage_second = NULL, $memory_limit = NULL) {
  $this->executable
    ->setMemoryLimit($memory_limit ?: $this->memoryLimit);
  $this->executable
    ->setMemoryUsage($memory_usage_first ?: $this->memoryLimit, $memory_usage_second ?: $this->memoryLimit);
  $this->executable
    ->setMemoryThreshold(0.85);
  if ($message) {
    $this->executable->message
      ->expects($this
      ->at(0))
      ->method('display')
      ->with($this
      ->callback(function ($subject) {
      return mb_stripos((string) $subject, 'reclaiming memory') !== FALSE;
    }));
    $this->executable->message
      ->expects($this
      ->at(1))
      ->method('display')
      ->with($this
      ->callback(function ($subject) use ($message) {
      return mb_stripos((string) $subject, $message) !== FALSE;
    }));
  }
  else {
    $this->executable->message
      ->expects($this
      ->never())
      ->method($this
      ->anything());
  }
  $result = $this->executable
    ->memoryExceeded();
  $this
    ->assertEquals($memory_exceeded, $result);
}