class MigrateStubTest

Same name in this branch
  1. 10 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest
Same name in other branches
  1. 9 core/modules/migrate/tests/src/Unit/MigrateStubTest.php \Drupal\Tests\migrate\Unit\MigrateStubTest
  2. 9 core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest
  3. 8.9.x core/modules/migrate/tests/src/Unit/MigrateStubTest.php \Drupal\Tests\migrate\Unit\MigrateStubTest
  4. 8.9.x core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest
  5. 11.x core/modules/migrate/tests/src/Unit/MigrateStubTest.php \Drupal\Tests\migrate\Unit\MigrateStubTest
  6. 11.x core/modules/migrate/tests/src/Kernel/MigrateStubTest.php \Drupal\Tests\migrate\Kernel\MigrateStubTest

Tests the migrate stub service.

@group migrate

@coversDefaultClass \Drupal\migrate\MigrateStub

Hierarchy

Expanded class hierarchy of MigrateStubTest

File

core/modules/migrate/tests/src/Unit/MigrateStubTest.php, line 25

Namespace

Drupal\Tests\migrate\Unit
View source
class MigrateStubTest extends UnitTestCase {
    
    /**
     * The plugin manager prophecy.
     *
     * @var \Prophecy\Prophecy\ObjectProphecy
     */
    protected $migrationPluginManager;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->migrationPluginManager = $this->prophesize(MigrationPluginManagerInterface::class);
    }
    
    /**
     * Tests stubbing.
     *
     * @covers ::createStub
     */
    public function testCreateStub() : void {
        $destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
        $destination_plugin->import(Argument::type(Row::class))
            ->willReturn([
            'id' => 2,
        ]);
        $source_plugin = $this->prophesize(MigrateSourceInterface::class);
        $source_plugin->getIds()
            ->willReturn([
            'id' => [
                'type' => 'integer',
            ],
        ]);
        $id_map = $this->prophesize(MigrateIdMapInterface::class);
        $migration = $this->prophesize(MigrationInterface::class);
        $migration->getIdMap()
            ->willReturn($id_map->reveal());
        $migration->getDestinationPlugin(TRUE)
            ->willReturn($destination_plugin->reveal());
        $migration->getProcessPlugins([])
            ->willReturn([]);
        $migration->getProcess()
            ->willReturn([]);
        $migration->getSourceConfiguration()
            ->willReturn([]);
        $migration->getSourcePlugin()
            ->willReturn($source_plugin->reveal());
        $this->migrationPluginManager
            ->createInstances([
            'test_migration',
        ])
            ->willReturn([
            $migration->reveal(),
        ]);
        $stub = new MigrateStub($this->migrationPluginManager
            ->reveal());
        $this->assertSame([
            'id' => 2,
        ], $stub->createStub('test_migration', [
            'id' => 1,
        ], []));
    }
    
    /**
     * Tests that an error is logged if the plugin manager throws an exception.
     */
    public function testExceptionOnPluginNotFound() : void {
        $this->migrationPluginManager
            ->createInstances([
            'test_migration',
        ])
            ->willReturn([]);
        $this->expectException(PluginNotFoundException::class);
        $this->expectExceptionMessage("Plugin ID 'test_migration' was not found.");
        $stub = new MigrateStub($this->migrationPluginManager
            ->reveal());
        $stub->createStub('test_migration', [
            1,
        ]);
    }
    
    /**
     * Tests that an error is logged on derived migrations.
     */
    public function testExceptionOnDerivedMigration() : void {
        $this->migrationPluginManager
            ->createInstances([
            'test_migration',
        ])
            ->willReturn([
            'test_migration:d1' => $this->prophesize(MigrationInterface::class)
                ->reveal(),
            'test_migration:d2' => $this->prophesize(MigrationInterface::class)
                ->reveal(),
        ]);
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('Cannot stub derivable migration "test_migration".  You must specify the id of a specific derivative to stub.');
        $stub = new MigrateStub($this->migrationPluginManager
            ->reveal());
        $stub->createStub('test_migration', [
            1,
        ]);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
MigrateStubTest::$migrationPluginManager protected property The plugin manager prophecy.
MigrateStubTest::setUp protected function Overrides UnitTestCase::setUp
MigrateStubTest::testCreateStub public function Tests stubbing.
MigrateStubTest::testExceptionOnDerivedMigration public function Tests that an error is logged on derived migrations.
MigrateStubTest::testExceptionOnPluginNotFound public function Tests that an error is logged if the plugin manager throws an exception.
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

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