1

I have the following Entity with Assert Validation:

/**
* Appointment
*
* @ORM\Table(name="appointment")
* @ORM\Entity(repositoryClass="AppointmentBundle\Entity\AppointmentRepository")
* @ORM\HasLifecycleCallbacks
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
* @Assert\Callback(methods={"customValidation"}, groups={"step2"})
*/
class Appointment {
   /**
    * @var \DateTime
    * @Assert\NotNull(message="form.appointment.requestdate", groups={"step1"})
    * @ORM\Column(name="request_date", type="date")
    * @JMS\Type("DateTime<'Y-m-d'>")
    */
   private $requestDate;

   /**
    * @var string
    *
    * @ORM\Column(name="delivery_time", type="string", length=5)
    * @Assert\Length(max=5)
    */
    private $deliveryTime;

    ...

    /**
     * @var string
     * @Assert\NotBlank(groups={"step2"})
     * @ORM\Column(name="lastname", type="string", length=64)
     * @Assert\Length(groups={"step2"}, max=64)
     */
     private $lastname;
}

I use this validation with form-binding. But now, I just want to validate this entity without a form-binding like this:

$appointment = new Appointment();

$validator = $this->get('validator');
$errors = $validator->validate($appointment);

But I always retrieve zero errors? Also when I leave lastname blank. Do I miss something?

Thanks in advance

1 Answer 1

3

Lastname will only be checked against the NotBlank when you use step2 validation group.

Try this:

$errors = $validator->validate($appointment, array('step2'));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.