function PluginFormFactoryTest::testCreateInstanceInvalidException

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php \Drupal\Tests\Core\Plugin\PluginFormFactoryTest::testCreateInstanceInvalidException()
  2. 8.9.x core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php \Drupal\Tests\Core\Plugin\PluginFormFactoryTest::testCreateInstanceInvalidException()
  3. 11.x core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php \Drupal\Tests\Core\Plugin\PluginFormFactoryTest::testCreateInstanceInvalidException()

@covers ::createInstance

File

core/tests/Drupal/Tests/Core/Plugin/PluginFormFactoryTest.php, line 144

Class

PluginFormFactoryTest
@coversDefaultClass \Drupal\Core\Plugin\PluginFormFactory @group Plugin

Namespace

Drupal\Tests\Core\Plugin

Code

public function testCreateInstanceInvalidException() : void {
    $this->expectException(InvalidPluginDefinitionException::class);
    $this->expectExceptionMessage('The "the_plugin_id" plugin did not specify a valid "invalid" form class, must implement \\Drupal\\Core\\Plugin\\PluginFormInterface');
    $expected = new \stdClass();
    $this->classResolver
        ->getInstanceFromDefinition(get_class($expected))
        ->willReturn($expected);
    $plugin = $this->prophesize(PluginWithFormsInterface::class);
    $plugin->getPluginId()
        ->willReturn('the_plugin_id');
    $plugin->hasFormClass('invalid')
        ->willReturn(TRUE);
    $plugin->getFormClass('invalid')
        ->willReturn(get_class($expected));
    $form_object = $this->manager
        ->createInstance($plugin->reveal(), 'invalid');
    $this->assertNull($form_object);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.