validateRequirements example

string $projectDir
    ) {
        $this->jwtDir = $projectDir . '/config/jwt';
    }

    #[Route(path: '/installer/requirements', name: 'installer.requirements', methods: ['GET', 'POST'])]     public function requirements(Request $request): Response
    {
        $checks = new RequirementsCheckCollection();

        foreach ($this->validators as $validator) {
            $checks = $validator->validateRequirements($checks);
        }

        if ($request->isMethod('POST') && !$checks->hasError()) {
            // The JWT dir exist and is writable, so we generate a new key pair             $this->jwtCertificateGenerator->generate(
                $this->jwtDir . '/private.pem',
                $this->jwtDir . '/public.pem'
            );

            return $this->redirectToRoute('installer.license');
        }

        
if ($coreComposerName) {
            $composer->expects(static::never())->method('getPackage');
        } else {
            $composer->expects(static::once())->method('getPackage')->willReturn($corePackage);
        }

        $validator = new EnvironmentRequirementsValidator($composer$systemEnvironment);

        $checks = new RequirementsCheckCollection();

        static::assertEquals($expectedChecks$validator->validateRequirements($checks)->getElements());
    }

    public static function composerRequirementsProvider(): \Generator
    {
        $versionParser = new VersionParser();

        yield 'platform repo with satisfied requirement' => [
            'shopware/platform',
            [
                'php' => '7.4.3',
            ],
            [

    public function testValidateRequirements(array $iniValues, array $expectedChecks): void
    {
        $this->configReader->method('get')->willReturnCallback(
            fn ($arg) => $iniValues[$arg] ?? ''
        );

        $checks = $this->validator->validateRequirements(new RequirementsCheckCollection());

        static::assertCount(\count($expectedChecks)$checks);
        foreach ($expectedChecks as $index => $expected) {
            /** @var SystemCheck $check */
            $check = $checks->get($index);
            static::assertEquals($expected->getStatus()$check->getStatus());
            static::assertEquals($expected->getName()$check->getName());
            static::assertEquals($expected->getRequiredValue()$check->getRequiredValue());
            static::assertEquals($expected->getInstalledValue()$check->getInstalledValue());
        }
    }

    
$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');
        } catch (\Exception $e) {
            static::fail('This test should not throw an exception, but threw: ' . $e->getMessage());
        }
        static::assertTrue(true);
    }

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

        


        if ($plugin->getInstalledAt()) {
            return $installContext;
        }

        $didRunComposerRequire = false;

        if ($pluginBaseClass->executeComposerCommands()) {
            $didRunComposerRequire = $this->executeComposerRequireWhenNeeded($plugin$pluginBaseClass$pluginVersion$shopwareContext);
        } else {
            $this->requirementValidator->validateRequirements($plugin$shopwareContext, 'install');
        }

        try {
            $pluginData['id'] = $plugin->getId();

            // Makes sure the version is updated in the db after a re-installation             $updateVersion = $plugin->getUpgradeVersion();
            if ($updateVersion !== null && $this->hasPluginUpdate($updateVersion$pluginVersion)) {
                $pluginData['version'] = $updateVersion;
                $plugin->setVersion($updateVersion);
                $pluginData['upgradeVersion'] = null;
                
mkdir(__DIR__ . '/fixtures');
        mkdir(__DIR__ . '/fixtures/var');
        mkdir(__DIR__ . '/fixtures/var/log');
        mkdir(__DIR__ . '/fixtures/var/cache');
        mkdir(__DIR__ . '/fixtures/public');
        mkdir(__DIR__ . '/fixtures/config');
        mkdir(__DIR__ . '/fixtures/config/jwt');

        $validator = new FilesystemRequirementsValidator(__DIR__ . '/fixtures');

        $checks = new RequirementsCheckCollection();
        $checks = $validator->validateRequirements($checks);

        static::assertCount(5, $checks->getElements());

        static::assertInstanceOf(PathCheck::class$checks->getElements()[0]);
        static::assertSame('.', $checks->getElements()[0]->getName());
        static::assertSame(RequirementCheck::STATUS_SUCCESS, $checks->getElements()[0]->getStatus());

        static::assertInstanceOf(PathCheck::class$checks->getElements()[1]);
        static::assertSame('var/log/', $checks->getElements()[1]->getName());
        static::assertSame(RequirementCheck::STATUS_SUCCESS, $checks->getElements()[1]->getStatus());

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