Skip to content

Instantly share code, notes, and snippets.

View jonathanfranks's full-sized avatar

J F jonathanfranks

  • Breakthrough
  • Evanston, IL
View GitHub Profile
@jonathanfranks
jonathanfranks / test.php
Created March 1, 2019 20:07
Mocking service container in D8 unit test
$fakeService = $this->createMock('Drupal\fake\Services\Fake');
$fakeService->method('serviceMethod')
->withAnyParameters()
->willReturn(0);
$container = new ContainerBuilder();
$container->set('fake.service_name', $fakeService);
\Drupal::setContainer($container);
@jonathanfranks
jonathanfranks / gist:10544cd4e1e6afe0afb9f1656c642d9b
Created April 22, 2021 15:31
Run migrate import with update option
$migration_id = 'xxx';
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = \Drupal::service('plugin.manager.migration')
->createInstance($migration_id);
$migration->getIdMap()->prepareUpdate();
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();