title: Symfony 2.5 addViolationAt deprecated, use buildViolation()
body: <p>I have been following the <a href="http://symfony.com/doc/current/cookbook/validation/custom_constraint.html#constraint-validators-with-dependencies" rel="noreferrer">cookbook</a> on how to create a class constraint validator and right now I am at the point where I am about to add the violation in the <code>validate()</code> function.</p>
  
  <p>However my IDE notifies me the functions <code>addViolation()</code> and <code>addViolationAt()</code> are deprecated.</p>
  
  <p>Can someone point me in the right direction on how to use the <a href="http://api.symfony.com/2.5/Symfony/Component/Validator/Context/ExecutionContextInterface.html#method_buildViolation" rel="noreferrer"><code>Context\ExecutionContextInterface::buildViolation()</code></a> function instead?</p>
  
  <p><code>$this-&gt;context</code> is an instance of <a href="http://api.symfony.com/2.0/Symfony/Component/Validator/ExecutionContext.html" rel="noreferrer"><code>Symfony\Component\Validator\ExecutionContext</code></a></p>
  
  <pre><code>class ProtocolClassValidator extends ConstraintValidator
  {
      public function validate($protocol, Constraint $constraint)
      {
          if ($protocol-&gt;getFoo() != $protocol-&gt;getBar()) {
              $this-&gt;context-&gt;addViolationAt(
                  'foo',
                  $constraint-&gt;message,
                  array(),
                  null
              );
          }
      }
  }
  </code></pre>
  
  <p>When changing the call <code>$this-&gt;context-&gt;addViolationAt()</code> to simply <code>$this-&gt;context-&gt;buildViolation()</code>, I get the following Exception:</p>
  
  <blockquote>
    <p>UndefinedMethodException: Attempted to call method "buildViolation" on
    class "Symfony\Component\Validator\ExecutionContext" in
    <em>stripped path</em>
    line 23. Did you mean to call: "addViolation"?</p>
  </blockquote>
  
  <p>and line 23 has the following code:</p>
  
  <pre><code>    $builder = $this-&gt;context-&gt;buildViolation($constraint-&gt;message)
      -&gt;atPath('formField')
      -&gt;addViolation();
  </code></pre>