noLabelProperty example

use Symfony\Component\HttpFoundation\Response;

/** * @internal * * @covers \Shopware\Core\System\CustomEntity\CustomEntityException */
class CustomEntityExceptionTest extends TestCase
{
    public function testNoLabelProperty(): void
    {
        $exception = CustomEntityException::noLabelProperty();

        static::assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        static::assertSame(CustomEntityException::CUSTOM_FIELDS_AWARE_NO_LABEL_PROPERTY, $exception->getErrorCode());
        static::assertSame('Entity must have a label property when it is custom field aware', $exception->getMessage());
    }

    public function testLabelPropertyNotDefined(): void
    {
        $labelProperty = 'some_label';
        $exception = CustomEntityException::labelPropertyNotDefined($labelProperty);

        
public function validate(CustomEntityXmlSchema $schema): void
    {
        if ($schema->getEntities() === null) {
            throw new \RuntimeException('No entities found in parsed xml file');
        }

        foreach ($schema->getEntities()->getEntities() as $entity) {
            if ($entity->isCustomFieldsAware()) {
                $label = $entity->getLabelProperty();

                if ($label === null) {
                    throw CustomEntityException::noLabelProperty();
                }

                if (!$entity->hasField($label)) {
                    throw CustomEntityException::labelPropertyNotDefined($label);
                }

                if (!$entity->getField($label) instanceof StringField) {
                    throw CustomEntityException::labelPropertyWrongType($label);
                }
            }

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