StaticKernelPluginLoader example

$command = $application->find('assets:install');

        return $command->run(new ArrayInput([]$command->getDefinition())$output);
    }

    private function rebootKernelWithoutPlugins(): ContainerInterface
    {
        /** @var Kernel $kernel */
        $kernel = $this->container->get('kernel');

        $classLoad = $kernel->getPluginLoader()->getClassLoader();
        $kernel->reboot(null, new StaticKernelPluginLoader($classLoad));

        return $kernel->getContainer();
    }
}
$classLoader->register();

        $original = KernelLifecycleManager::getKernel();

        $oldCacheDirs = [];
        for ($i = 0; $i < 2; ++$i) {
            $class = KernelLifecycleManager::getKernelClass();
            /** @var Kernel $kernel */
            $kernel = new $class(
                'test',
                true,
                new StaticKernelPluginLoader($classLoader),
                Uuid::randomHex(),
                '1.0.0@' . $i . '1eec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33',
                $original->getContainer()->get(Connection::class)
            );

            $kernel->boot();
            $oldCacheDir = $kernel->getCacheDir();
            static::assertFileExists($oldCacheDir);
            $kernel->shutdown();
            $oldCacheDirs[] = $oldCacheDir;
        }
        
static::assertTrue($this->containerCacheExists());
    }

    private function createTestCacheDirectory(): string
    {
        $kernelClass = KernelLifecycleManager::getKernelClass();
        /** @var Kernel $newTestKernel */
        $newTestKernel = new $kernelClass(
            'test',
            true,
            new StaticKernelPluginLoader(KernelLifecycleManager::getClassLoader()),
            Uuid::randomHex(),
            '2.2.2',
            $this->getContainer()->get(Connection::class)
        );

        $newTestKernel->boot();
        $cacheDir = $newTestKernel->getCacheDir();
        $newTestKernel->shutdown();

        return $cacheDir;
    }

    

class KernelPluginLoaderTest extends TestCase
{
    /** * @dataProvider classLoaderDataProvider */
    public function testClassMapAuthoritativeWillBeDeactivated(bool $enabled): void
    {
        $classLoader = new ClassLoader();
        $classLoader->setClassMapAuthoritative($enabled);

        $fakeLoader = new StaticKernelPluginLoader(
            $classLoader,
            null,
            [
                [
                    'name' => 'ExampleBundle',
                    'baseClass' => ExampleBundle::class,
                    'path' => __DIR__ . '/../_fixtures/ExampleBundle',
                    'active' => true,
                    'managedByComposer' => false,
                    'autoload' => [
                        'psr-4' => [
                            
<?php declare(strict_types=1);

namespace Shopware\Core\DevOps\StaticAnalyze\PHPStan;

use Shopware\Core\DevOps\StaticAnalyze\StaticAnalyzeKernel;
use Shopware\Core\Framework\Plugin\KernelPluginLoader\StaticKernelPluginLoader;
use Symfony\Bundle\FrameworkBundle\Console\Application;

$classLoader = require __DIR__ . '/phpstan-bootstrap.php';

$pluginLoader = new StaticKernelPluginLoader($classLoader);

$kernel = new StaticAnalyzeKernel('phpstan_dev', true, $pluginLoader, 'phpstan-test-cache-id');
$kernel->boot();

return new Application($kernel);
        $eventDispatcherWithoutPlugins->dispatch(new UpdatePostPrepareEvent($context$currentVersion$newVersion));

        return self::SUCCESS;
    }

    private function rebootKernelWithoutPlugins(): ContainerInterface
    {
        /** @var Kernel $kernel */
        $kernel = $this->container->get('kernel');

        $classLoad = $kernel->getPluginLoader()->getClassLoader();
        $kernel->reboot(null, new StaticKernelPluginLoader($classLoad));

        return $kernel->getContainer();
    }
}
return $dir;
    })());
}

$_ENV['PROJECT_ROOT'] = $_SERVER['PROJECT_ROOT'] = TEST_PROJECT_DIR;
$classLoader = require TEST_PROJECT_DIR . '/vendor/autoload.php';

if (class_exists(Dotenv::class) && (file_exists(TEST_PROJECT_DIR . '/.env.local.php') || file_exists(TEST_PROJECT_DIR . '/.env') || file_exists(TEST_PROJECT_DIR . '/.env.dist'))) {
    (new Dotenv())->usePutenv()->bootEnv(TEST_PROJECT_DIR . '/.env');
}

$pluginLoader = new StaticKernelPluginLoader($classLoader);
$kernel = new StaticAnalyzeKernel('phpstan_dev', true, $pluginLoader, 'phpstan-test-cache-id');
$kernel->boot();

return $classLoader;
$kernelMock = $this->createMock(KernelInterface::class);
        $kernelMock->expects(static::once())
            ->method('getBundle')
            ->with('bundleName')
            ->willThrowException(new \InvalidArgumentException());

        $filesystem = new Filesystem(new MemoryFilesystemAdapter());
        $assetService = new AssetService(
            $filesystem,
            $filesystem,
            $kernelMock,
            new StaticKernelPluginLoader($this->createMock(ClassLoader::class)),
            $this->createMock(CacheInvalidator::class),
            $this->createMock(AbstractAppLoader::class),
            new ParameterBag(['shopware.filesystem.asset.type' => 's3'])
        );

        static::expectException(PluginNotFoundException::class);
        $assetService->copyAssetsFromBundle('bundleName');
    }

    public function testCopyAssetsFromBundlePlugin(): void
    {
        
use Symfony\Component\DependencyInjection\Definition;

/** * @internal */
class StaticKernelPluginLoaderTest extends TestCase
{
    use PluginIntegrationTestBehaviour;

    public function testNoPlugins(): void
    {
        $loader = new StaticKernelPluginLoader($this->classLoader, null, []);
        $loader->initializePlugins(TEST_PROJECT_DIR);

        static::assertEmpty($loader->getPluginInfos());
        static::assertEmpty($loader->getPluginInstances()->all());
    }

    public function testNoKernelPluginsWithoutInit(): void
    {
        $activePluginData = $this->getActivePlugin()->jsonSerialize();
        $loader = new StaticKernelPluginLoader($this->classLoader, null, [$activePluginData]);

        
'offset' => $result->getOffset(),
            'total' => $result->getTotal(),
        ]);
    }

    private function rebootKernelWithoutPlugins(): ContainerInterface
    {
        /** @var Kernel $kernel */
        $kernel = $this->container->get('kernel');

        $classLoad = $kernel->getPluginLoader()->getClassLoader();
        $kernel->reboot(null, new StaticKernelPluginLoader($classLoad));

        return $kernel->getContainer();
    }
}
$this->getContainer()->get(Connection::class)
        );
    }

    public function testGetPluginPath(): void
    {
        $kernelMock = $this->createMock(Kernel::class);

        $loader = $this->createMock(ClassLoader::class);
        $loader->method('findFile')->willReturn(__DIR__);

        $kernelPluginLoader = new StaticKernelPluginLoader(
            $loader,
            null,
            [
                [
                    'name' => 'FakePlugin',
                    'active' => true,
                    'baseClass' => FakePlugin::class,
                    'path' => 'src/FakePlugin',
                    'autoload' => [
                        'psr-4' => [
                            'Shopware\\FakePlugin\\' => 'src/',
                        ],
foreach ($plugins as $i => $pluginData) {
            if ($pluginData['baseClass'] === $plugin->getBaseClass()) {
                $plugins[$i]['active'] = $plugin->getActive();
            }
        }

        /* * Reboot kernel with $plugin active=true. * * All other Requests won't have this plugin active until it's updated in the db */
        $tmpStaticPluginLoader = new StaticKernelPluginLoader($pluginLoader->getClassLoader()$pluginDir$plugins);
        $kernel->reboot(null, $tmpStaticPluginLoader);

        try {
            $newContainer = $kernel->getContainer();
        } catch (\LogicException) {
            // If symfony throws an exception when calling getContainer on a not booted kernel and catch it here             throw new \RuntimeException('Failed to reboot the kernel');
        }

        $this->container = $newContainer;
        $this->eventDispatcher = $newContainer->get('event_dispatcher');
    }

                ['code' => $expectedLocale]
            )
            ->willReturn($returns);

        return $connection;
    }

    private function getKernelWithNoPlugins(): Kernel
    {
        $pluginLoader = new StaticKernelPluginLoader(new ClassLoader());

        return new Kernel(
            'dev',
            false,
            $pluginLoader,
            'foobar'
        );
    }

    /** * @return array<string, array<string, array<string, string>>> */

            if ($existingConnection === null) {
                $existingConnection = self::$connection = $kernelClass::getConnection();
            }

            // force connection to database             $existingConnection->fetchOne('SELECT 1');

            $pluginLoader = new DbalKernelPluginLoader(self::$classLoader, null, $existingConnection);
        } catch (\Throwable) {
            // if we don't have database yet, we'll boot the kernel without plugins             $pluginLoader = new StaticKernelPluginLoader(self::$classLoader);
        }

        return new $kernelClass($env$debug$pluginLoader$cacheId, null, $existingConnection$projectDir);
    }

    /** * @return class-string<Kernel> */
    public static function getKernelClass(): string
    {
        if (!class_exists($class = (string) EnvironmentHelper::getVariable('KERNEL_CLASS', Kernel::class))) {
            
$serviceContainer = $this->kernel->getContainer()
                ->get('test.service_container');
            $serviceContainer->get('cache.object')
                ->clear();
        }
    }

    public function testWithDisabledPlugins(): void
    {
        $this->insertPlugin($this->getActivePlugin());

        $loader = new StaticKernelPluginLoader($this->classLoader);
        $this->kernel = $this->makeKernel($loader);
        $this->kernel->boot();

        static::assertEmpty($this->kernel->getPluginLoader()->getPluginInstances()->all());
    }

    public function testInactive(): void
    {
        $this->insertPlugin($this->getInstalledInactivePlugin());

        $loader = new DbalKernelPluginLoader($this->classLoader, null, $this->connection);
        
Home | Imprint | This part of the site doesn't use cookies.