TestBootstrapper example


    final public const TEST_IMAGE = __DIR__ . '/../../../../../../src/Core/Content/Test/Media/fixtures/shopware-logo.png';

    private FileFetcher $fileFetcher;

    private bool $mediaDirCreated = false;

    protected function setUp(): void
    {
        $this->fileFetcher = new FileFetcher(new FileUrlValidator());

        $projectDir = (new TestBootstrapper())->getProjectDir();
        if (!\is_dir($projectDir . '/public/media')) {
            mkdir($projectDir . '/public/media');
            $this->mediaDirCreated = true;
        }

        \copy(self::TEST_IMAGE, $projectDir . '/public/media/shopware-logo.png');
    }

    protected function tearDown(): void
    {
        $projectDir = (new TestBootstrapper())->getProjectDir();
        

        if (!$this->resolver instanceof OptionsResolver) {
            throw new \Exception(self::class D '::configure must be called before running the load method');
        }

        $_SERVER['APP_ENV'] = 'test';

        if (isset($_SERVER['DATABASE_URL'])) {
            $url = $_SERVER['DATABASE_URL'];
        }

        $bootstrapper = (new TestBootstrapper())
            ->setOutput(new ConsoleOutput())
            ->setForceInstall(static::parseEnvVar('FORCE_INSTALL', true))
            ->setForceInstallPlugins(static::parseEnvVar('FORCE_INSTALL_PLUGINS', true))
            ->setPlatformEmbedded(static::parseEnvVar('PLATFORM_EMBEDDED'))
            ->setBypassFinals(static::parseEnvVar('BYPASS_FINALS'))
            ->setEnableCommercial(static::parseEnvVar('ENABLE_COMMERCIAL'))
            ->setLoadEnvFile(static::parseEnvVar('LOAD_ENV_FILE', true))
            ->setProjectDir($_ENV['PROJECT_DIR'] ?? null)
            ->bootstrap();

        (new Fixtures())->load(__DIR__ . '/data.json');

        
        static::assertTrue($kernel->getContainer()->hasParameter('kernel.shopware_version_revision'));

        static::assertEquals(
            [
                'FrameworkBundle' => FrameworkBundle::class,
                'TwigBundle' => TwigBundle::class,
                'Installer' => Installer::class,
            ],
            $kernel->getContainer()->getParameter('kernel.bundles')
        );

        $projectDir = (new TestBootstrapper())->getProjectDir();

        static::assertSame($projectDir$kernel->getContainer()->getParameter('kernel.project_dir'));
        static::assertSame($projectDir . '/var/cache/composer', EnvironmentHelper::getVariable('COMPOSER_HOME'));
    }
}
<?php declare(strict_types=1);

namespace Shopware\Core;

require __DIR__ . '/TestBootstrapper.php';

(new TestBootstrapper())
    ->setPlatformEmbedded(false)
    ->setEnableCommercial()
    ->setBypassFinals(false)
    ->bootstrap();
// Boot Kernel once to initialize the feature flags KernelLifecycleManager::prepare($classloader);

KernelLifecycleManager::bootKernel();
KernelLifecycleManager::ensureKernelShutdown();

// Boot env if (!class_exists(Dotenv::class)) {
    throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
}

$envFilePath = (new TestBootstrapper())->getProjectDir() . '/.env';
if (is_file($envFilePath) || is_file($envFilePath . '.dist') || is_file($envFilePath . '.local.php')) {
    (new Dotenv())->usePutenv()->bootEnv($envFilePath);
}
/** * @internal * * @covers \Shopware\Core\Framework\Plugin\Requirement\RequirementsValidator */
class RequirementsValidatorTest extends TestCase
{
    private string $projectDir;

    protected function setUp(): void
    {
        $this->projectDir = (new TestBootstrapper())->getProjectDir();
    }

    public function testValidateRequirementsValid(): void
    {
        $path = __DIR__ . '/_fixture/SwagRequirementValidTest';
        $path = str_replace($this->projectDir, '', $path);

        $plugin = $this->createPlugin($path);

        try {
            $this->createValidator()->validateRequirements($plugin, Context::createDefaultContext(), 'test');
        }
use Shopware\Core\TestBootstrapper;

/** * @internal * * @covers \Shopware\Core\Installer\Database\MigrationCollectionFactory */
class MigrationCollectionFactoryTest extends TestCase
{
    public function testGetMigrationCollectionLoader(): void
    {
        $factory = new MigrationCollectionFactory((new TestBootstrapper())->getProjectDir());
        $loader = $factory->getMigrationCollectionLoader(
            $this->createMock(Connection::class)
        );

        static::assertArrayHasKey('core', $loader->collectAll());
        static::assertArrayHasKey('core.V6_3', $loader->collectAll());
        static::assertArrayHasKey('core.V6_4', $loader->collectAll());
        static::assertArrayHasKey('core.V6_5', $loader->collectAll());
    }
}
<?php declare(strict_types=1);

namespace Shopware\Tests\Bench;

require __DIR__ . '/../../../src/Core/TestBootstrapper.php';

use Shopware\Core\TestBootstrapper;

(new TestBootstrapper())
    ->setForceInstall(false)
    ->setPlatformEmbedded(false)
    ->setBypassFinals(false)
    ->bootstrap();
Home | Imprint | This part of the site doesn't use cookies.