class MigrateExecutableMemoryExceededTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/migrate/tests/src/Unit/MigrateExecutableMemoryExceededTest.php \Drupal\Tests\migrate\Unit\MigrateExecutableMemoryExceededTest
Tests the \Drupal\migrate\MigrateExecutable::memoryExceeded() method.
@group migrate
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
- class \Drupal\Tests\migrate\Unit\MigrateExecutableMemoryExceededTest
- class \Drupal\Tests\migrate\Unit\MigrateTestCase
Expanded class hierarchy of MigrateExecutableMemoryExceededTest
File
- core/
modules/ migrate/ tests/ src/ Unit/ MigrateExecutableMemoryExceededTest.php, line 15 - Contains \Drupal\Tests\migrate\Unit\MigrateExecutableMemoryExceededTest.
Namespace
Drupal\Tests\migrate\UnitView source
class MigrateExecutableMemoryExceededTest extends MigrateTestCase {
/**
* The mocked migration entity.
*
* @var \Drupal\migrate\Entity\MigrationInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $migration;
/**
* The mocked migrate message.
*
* @var \Drupal\migrate\MigrateMessageInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $message;
/**
* The tested migrate executable.
*
* @var \Drupal\Tests\migrate\Unit\TestMigrateExecutable
*/
protected $executable;
/**
* The migration configuration, initialized to set the ID to test.
*
* @var array
*/
protected $migrationConfiguration = array(
'id' => 'test',
);
/**
* php.init memory_limit value.
*/
protected $memoryLimit = 10000000;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->migration = $this
->getMigration();
$this->message = $this
->getMock('Drupal\\migrate\\MigrateMessageInterface');
$this->executable = new TestMigrateExecutable($this->migration, $this->message);
$this->executable
->setStringTranslation($this
->getStringTranslationStub());
}
/**
* Runs the actual test.
*
* @param string $message
* The second message to assert.
* @param bool $memory_exceeded
* Whether to test the memory exceeded case.
* @param int $memory_usage_first
* (optional) The first memory usage value.
* @param int $memory_usage_second
* (optional) The fake amount of memory usage reported after memory reclaim.
* @param int $memory_limit
* (optional) The memory limit.
*/
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
->stringContains('reclaiming memory'));
$this->executable->message
->expects($this
->at(1))
->method('display')
->with($this
->stringContains($message));
}
else {
$this->executable->message
->expects($this
->never())
->method($this
->anything());
}
$result = $this->executable
->memoryExceeded();
$this
->assertEquals($memory_exceeded, $result);
}
/**
* Tests memoryExceeded method when a new batch is needed.
*/
public function testMemoryExceededNewBatch() {
// First case try reset and then start new batch.
$this
->runMemoryExceededTest('starting new batch', TRUE);
}
/**
* Tests memoryExceeded method when enough is cleared.
*/
public function testMemoryExceededClearedEnough() {
$this
->runMemoryExceededTest('reclaimed enough', FALSE, $this->memoryLimit, $this->memoryLimit * 0.75);
}
/**
* Tests memoryExceeded when memory usage is not exceeded.
*/
public function testMemoryNotExceeded() {
$this
->runMemoryExceededTest('', FALSE, floor($this->memoryLimit * 0.85) - 1);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateExecutableMemoryExceededTest:: |
protected | property | The tested migrate executable. | |
MigrateExecutableMemoryExceededTest:: |
protected | property | php.init memory_limit value. | |
MigrateExecutableMemoryExceededTest:: |
protected | property | The mocked migrate message. | |
MigrateExecutableMemoryExceededTest:: |
protected | property | The mocked migration entity. | |
MigrateExecutableMemoryExceededTest:: |
protected | property |
The migration configuration, initialized to set the ID to test. Overrides MigrateTestCase:: |
|
MigrateExecutableMemoryExceededTest:: |
protected | function | Runs the actual test. | |
MigrateExecutableMemoryExceededTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MigrateExecutableMemoryExceededTest:: |
public | function | Tests memoryExceeded method when enough is cleared. | |
MigrateExecutableMemoryExceededTest:: |
public | function | Tests memoryExceeded method when a new batch is needed. | |
MigrateExecutableMemoryExceededTest:: |
public | function | Tests memoryExceeded when memory usage is not exceeded. | |
MigrateTestCase:: |
protected | property | ||
MigrateTestCase:: |
protected | property | Local store for mocking setStatus()/getStatus(). | |
MigrateTestCase:: |
protected | function | Generates a table schema from a row. | |
MigrateTestCase:: |
protected | function | Get an SQLite database connection object for use in tests. | |
MigrateTestCase:: |
protected | function | Retrieve a mocked migration. | |
MigrateTestCase:: |
protected | function | 1 | |
MigrateTestCase:: |
public | function | Tests a query | |
MigrateTestCase:: |
protected | function | Asserts tested values during test retrieval. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |