function UnitTestCase::getBlockMockWithMachineName
Mocks a block with a block plugin.
Parameters
string $machine_name: The machine name of the block plugin.
Return value
\Drupal\block\BlockInterface|\PHPUnit\Framework\MockObject\MockObject The mocked block.
Deprecated
in drupal:8.5.0 and is removed from drupal:9.0.0. Unit test base classes should not have dependencies on extensions. Set up mocks in individual tests.
See also
https://www.drupal.org/node/2896072
1 call to UnitTestCase::getBlockMockWithMachineName()
- UnitTestCaseDeprecationTest::testDeprecatedGetBlockMockWithMachineName in core/
tests/ Drupal/ Tests/ UnitTestCaseDeprecationTest.php - @covers ::getBlockMockWithMachineName @expectedDeprecation Drupal\Tests\UnitTestCase::getBlockMockWithMachineName is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Unit test base classes should not have dependencies on extensions.…
1 method overrides UnitTestCase::getBlockMockWithMachineName()
- BlockFormTest::getBlockMockWithMachineName in core/
modules/ block/ tests/ src/ Unit/ BlockFormTest.php - Mocks a block with a block plugin.
File
-
core/
tests/ Drupal/ Tests/ UnitTestCase.php, line 203
Class
- UnitTestCase
- Provides a base class and helpers for Drupal unit tests.
Namespace
Drupal\TestsCode
protected function getBlockMockWithMachineName($machine_name) {
$plugin = $this->getMockBuilder('Drupal\\Core\\Block\\BlockBase')
->disableOriginalConstructor()
->getMock();
$plugin->expects($this->any())
->method('getMachineNameSuggestion')
->will($this->returnValue($machine_name));
$block = $this->getMockBuilder('Drupal\\block\\Entity\\Block')
->disableOriginalConstructor()
->getMock();
$block->expects($this->any())
->method('getPlugin')
->will($this->returnValue($plugin));
@trigger_error(__METHOD__ . ' is deprecated in Drupal 8.5.x, will be removed before Drupal 9.0.0. Unit test base classes should not have dependencies on extensions. Set up mocks in individual tests.', E_USER_DEPRECATED);
return $block;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.