ValidationResult example

$checkedDirectories = [];

        $fullPath = rtrim($this->rootDir . '/');
        $checkedDirectories[] = $fullPath;

        $directories = array_merge(
            $directories,
            $this->filesystem->checkSingleDirectoryPermissions($fullPath, true)
        );

        if (empty($directories)) {
            return new ValidationResult(
                'writeableCheck',
                true,
                'writeableCheckValid',
                ['checkedDirectories' => implode('<br>', $checkedDirectories)]
            );
        }

        return new ValidationResult(
            'writeableCheck',
            false,
            'writeableCheckFailed',
            [
$content = $response->getContent();

        static::assertJson((string) $content);
        static::assertSame('{}', $content);
    }

    public function testCheckForRequirements(): void
    {
        $writeableCheck = $this->createMock(WriteableCheck::class);
        $writeableCheck
            ->method('check')
            ->willReturn(new ValidationResult('writeable', false, 'message'));

        $licenseCheck = $this->createMock(LicenseCheck::class);
        $licenseCheck
            ->method('check')
            ->willReturn(new ValidationResult('license', false, 'message'));

        $updateController = new UpdateController(
            $this->createMock(ApiClient::class),
            $writeableCheck,
            $licenseCheck,
            $this->createMock(ExtensionCompatibility::class),
            
use Shopware\Core\Framework\Update\Struct\ValidationResult;

/** * @internal * * @covers \Shopware\Core\Framework\Update\Struct\ValidationResult */
class ValidationResultTest extends TestCase
{
    public function testCreateResult(): void
    {
        $result = new ValidationResult('name', true, 'message', ['var' => 'value']);
        $vars = $result->getVars();

        static::assertSame('name', $vars['name']);
        static::assertTrue($vars['result']);
        static::assertSame('message', $vars['message']);
        static::assertSame(['var' => 'value']$vars['vars']);

        static::assertSame('update_api_validation_result', $result->getApiAlias());
    }
}
public function __construct(
        private readonly SystemConfigService $systemConfigService,
        private readonly StoreClient $storeClient
    ) {
    }

    public function check(): ValidationResult
    {
        $licenseHost = $this->systemConfigService->get('core.store.licenseHost');

        if (empty($licenseHost) || $this->storeClient->isShopUpgradeable()) {
            return new ValidationResult('validShopwareLicense', true, 'validShopwareLicense');
        }

        return new ValidationResult('invalidShopwareLicense', false, 'invalidShopwareLicense');
    }
}
Home | Imprint | This part of the site doesn't use cookies.