PathCheck example



    public function __construct(private readonly string $projectDir)
    {
    }

    public function validateRequirements(RequirementsCheckCollection $checks): RequirementsCheckCollection
    {
        foreach (self::NEEDED_PATHS as $path) {
            $absolutePath = $this->projectDir . '/' . $path;

            $checks->add(new PathCheck(
                $path,
                $this->existsAndIsWritable($absolutePath) ? RequirementCheck::STATUS_SUCCESS : RequirementCheck::STATUS_ERROR
            ));
        }

        return $checks;
    }

    private function existsAndIsWritable(string $path): bool
    {
        return file_exists($path) && is_readable($path) && is_writable($path);
    }
/** * @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 */
    

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',
                
Home | Imprint | This part of the site doesn't use cookies.