TestExtension example

/** * @author Bernhard Schussek <bschussek@gmail.com> */
class FormRegistryTest extends TestCase
{
    private FormRegistry $registry;
    private TestExtension $extension1;
    private TestExtension $extension2;

    protected function setUp(): void
    {
        $this->extension1 = new TestExtension(new NullFormTypeGuesser());
        $this->extension2 = new TestExtension(new NullFormTypeGuesser());
        $this->registry = new FormRegistry([
            $this->extension1,
            $this->extension2,
        ]new ResolvedFormTypeFactory());
    }

    public function testGetTypeFromExtension()
    {
        $type = new FooType();
        $this->extension2->addType($type);

        
/** * @coversDefaultClass \Drupal\Core\Extension\ExtensionList * @group Extension */
class ExtensionListTest extends UnitTestCase {

  /** * @covers ::getName */
  public function testGetNameWithNonExistingExtension() {
    [$cache$info_parser$module_handler$state] = $this->getMocks();
    $test_extension_list = new TestExtension($this->randomMachineName(), 'test_extension', $cache->reveal()$info_parser->reveal()$module_handler->reveal()$state->reveal(), 'testing');

    $extension_discovery = $this->prophesize(ExtensionDiscovery::class);
    $extension_discovery->scan('test_extension')->willReturn([]);
    $test_extension_list->setExtensionDiscovery($extension_discovery->reveal());

    $this->expectException(UnknownExtensionException::class);
    $test_extension_list->getName('test_name');
  }

  /** * @covers ::getName */
Home | Imprint | This part of the site doesn't use cookies.