MigrationSource example

public function collectAllForVersion(string $version, string $mode = self::VERSION_SELECTION_ALL): MigrationCollection
    {
        $safeMajorVersion = $this->getLastSafeMajorVersion($version$mode);

        $namespaces = [];
        for ($major = 3; $safeMajorVersion >= 3 && $major <= $safeMajorVersion; ++$major) {
            $namespaces[] = $this->getSource('core.V6_' . $major);
        }
        $namespaces[] = $this->getSource('core');

        $source = new MigrationSource('allForVersion', $namespaces);

        return new MigrationCollection($source$this->migrationRuntime, $this->connection, $this->logger);
    }

    public function getLastSafeMajorVersion(string $currentVersion, string $mode = self::VERSION_SELECTION_ALL): int
    {
        if (!\in_array($mode, self::VALID_VERSION_SELECTION_SAFE_VALUES, true)) {
            throw new \RuntimeException(sprintf(
                'mode needs to be one of these values: "%s"',
                implode('", "', self::VALID_VERSION_SELECTION_SAFE_VALUES)
            ));
        }
public static function dataProviderForTestPostEventNullsPayload(): array
    {
        $plugin = new PluginEntity();
        $plugin->setName('TestPlugin');
        $plugin->setBaseClass(RulePlugin::class);
        $plugin->setPath('');

        $context = Context::createDefaultContext();
        $rulePlugin = new RulePlugin(false, '');

        $collection = new MigrationCollection(
            new MigrationSource('asd', []),
            new MigrationRuntime(new NullConnection()new NullLogger()),
            new NullConnection()
        );

        return [
            [new PluginPostInstallEvent($pluginnew InstallContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostActivateEvent($pluginnew ActivateContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostUpdateEvent($pluginnew UpdateContext($rulePlugin$context, '', '', $collection, ''))],
            [new PluginPostDeactivateEvent($pluginnew DeactivateContext($rulePlugin$context, '', '', $collection))],
            [new PluginPostUninstallEvent($pluginnew UninstallContext($rulePlugin$context, '', '', $collection, true))],
        ];
    }


    public function testCommandMigrateCacheClearBehaviourWithoutMigrations(): void
    {
        static::assertSame(0, $this->getMigrationCount(true));

        $connection = $this->getConnection();
        $loader = $this->getMockBuilder(MigrationCollectionLoader::class)->disableOriginalConstructor()->getMock();

        $loader->expects(static::once())->method('collect')->willReturn(
            new MigrationCollection(
                new MigrationSource(''),
                new MigrationRuntime($connectionnew NullLogger()),
                $connection
            )
        );

        $cache = $this->getMockBuilder(TagAwareAdapter::class)->disableOriginalConstructor()->getMock();
        $cache->expects(static::never())->method('clear');

        $command = new MigrationCommand($loader$cache$this->getContainer()->getParameter('kernel.shopware_version'));

        $command->run(new ArrayInput(['--all' => true, 'identifier' => [self::INTEGRATION_IDENTIFIER()]])new BufferedOutput());

        

        $pattern = $this->getContainer()->get('Shopware\Core\Framework\Migration\MigrationSource.core.V6_3')->getNamespacePattern();

        static::assertSame($shouldMatch(bool) preg_match("/$pattern/", $subject$subject));
    }

    /** * @dataProvider provideUnitTestData */
    public function testUnitRegex(string $subject, bool $shouldMatch): void
    {
        $source = new MigrationSource('tmp', [
            __DIR__ . '/1' => 'My\Test\Namespace',
            __DIR__ . '/2' => 'My\Test\Namespace2',
            __DIR__ . '/3' => 'My\Other\Namespace',
        ]);

        $pattern = $source->getNamespacePattern();

        static::assertSame($shouldMatch(bool) preg_match("/$pattern/", $subject$subject));
    }

    public function testNestedMigrationSources(): void
    {
new MigrationRuntime($connectionnew NullLogger()),
            $this->collect()
        );
    }

    /** * @return list<MigrationSource> */
    private function collect(): array
    {
        return [
            new MigrationSource('core', []),
            $this->createMigrationSource('V6_3'),
            $this->createMigrationSource('V6_4'),
            $this->createMigrationSource('V6_5'),
            $this->createMigrationSource('V6_6'),
        ];
    }

    private function createMigrationSource(string $version): MigrationSource
    {
        if (file_exists($this->projectDir . '/platform/src/Core/schema.sql')) {
            $coreBasePath = $this->projectDir . '/platform/src/Core';
            
$pluginBaseClass->getPath() . str_replace(
                $pluginBaseClass->getNamespace(),
                '',
                $pluginBaseClass->getMigrationNamespace()
            )
        );

        if (!is_dir($migrationPath)) {
            return $this->migrationLoader->collect('null');
        }

        $this->migrationLoader->addSource(new MigrationSource($pluginBaseClass->getName()[
            $migrationPath => $pluginBaseClass->getMigrationNamespace(),
        ]));

        $collection = $this->migrationLoader
            ->collect($pluginBaseClass->getName());

        $collection->sync();

        return $collection;
    }

    
trait MigrationTestBehaviour
{
    /** * @before */
    public function addMigrationSources(): void
    {
        $loader = $this->getContainer()->get(MigrationCollectionLoader::class);

        $loader->addSource(
            new MigrationSource(
                '_test_migrations_invalid_namespace',
                [__DIR__ . '/_test_migrations_invalid_namespace' => 'Shopware\Core\Framework\Test\Migration\_test_migrations_invalid_namespace']
            )
        );

        $loader->addSource(
            new MigrationSource(
                '_test_migrations_valid',
                [__DIR__ . '/_test_migrations_valid' => 'Shopware\Core\Framework\Test\Migration\_test_migrations_valid']
            )
        );

        
Home | Imprint | This part of the site doesn't use cookies.