labelPropertyNotDefined example



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

            foreach ($entity->getFields() as $field) {
                if ($field instanceof OneToManyField) {
                    $this->validateAssociation($field);
                }
            }

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

        static::assertSame(Response::HTTP_INTERNAL_SERVER_ERROR, $exception->getStatusCode());
        static::assertSame(CustomEntityException::CUSTOM_FIELDS_AWARE_LABEL_PROPERTY_NOT_DEFINED, $exception->getErrorCode());
        static::assertSame('Entity label_property "some_label" is not defined in fields', $exception->getMessage());
    }

    public function testLabelPropertyWrongType(): void
    {
        $labelProperty = 'some_label';
        $exception = CustomEntityException::labelPropertyWrongType($labelProperty);

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