RequirementsCheckCollection example

$composer = $this->createMock(Composer::class);
        $composer->method('getRepositoryManager')->willReturn($repoManagerMock);

        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',
            [
                

class RequirementsControllerTest extends TestCase
{
    use InstallerControllerTestTrait;

    public function testRequirementsRouteValidatesAndRendersChecks(): void
    {
        $request = new Request();
        $request->setMethod('GET');

        $checks = new RequirementsCheckCollection([new PathCheck('check', RequirementCheck::STATUS_SUCCESS)]);

        $validator = $this->createMock(RequirementsValidatorInterface::class);
        $validator->expects(static::once())
            ->method('validateRequirements')
            ->with(static::isInstanceOf(RequirementsCheckCollection::class))
            ->willReturn($checks);

        $twig = $this->createMock(Environment::class);
        $twig->expects(static::once())->method('render')
            ->with(
                '@Installer/installer/requirements.html.twig',
                

    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());
        }
    }

    

        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());

        
use Shopware\Core\Installer\Requirements\Struct\SystemCheck;

/** * @internal * * @covers \Shopware\Core\Installer\Requirements\Struct\RequirementsCheckCollection */
class RequirementsCheckCollectionTest extends TestCase
{
    public function testGetExpectedClass(): void
    {
        $collection = new RequirementsCheckCollection();

        $collection->add(new PathCheck('name', RequirementCheck::STATUS_SUCCESS));

        static::expectException(\InvalidArgumentException::class);
        $collection->add(new ProductEntity()); /** @phpstan-ignore-line */
    }

    /** * @param RequirementCheck[] $elements * @param RequirementCheck[] $expected * * @dataProvider pathCheckProvider */
public function __construct(
        private readonly iterable $validators,
        private readonly JwtCertificateGenerator $jwtCertificateGenerator,
        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'
            );

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