<p dir="auto">I have an error with validation unique entity on date time fields<br>
Here is a sample code :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="namespace xxx\yyyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;

/**
 * xxx\yyyBundle\Entity\Planning
 *
 * @ORM\Entity(repositoryClass=&quot;xxx\yyyBundle\Repository\PlanningRepository&quot;)
 * @DoctrineAssert\UniqueEntity(fields={&quot;day&quot;})
 */
class Planning
{
    /**
     * @var integer $id
     *
     * @ORM\Id
     * @ORM\Column(name=&quot;id&quot;, type=&quot;smallint&quot;)
     * @ORM\GeneratedValue(strategy=&quot;AUTO&quot;)
     */
    private $id;

    /**
     * @var datetime $day
     *
     * @ORM\Column(name=&quot;day&quot;, type=&quot;date&quot;, unique=true, nullable=false)
     * @Assert\NotNull()
     * @Assert\Date()
     */
    private $day;"><pre class="notranslate"><code class="notranslate">namespace xxx\yyyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints as DoctrineAssert;

/**
 * xxx\yyyBundle\Entity\Planning
 *
 * @ORM\Entity(repositoryClass="xxx\yyyBundle\Repository\PlanningRepository")
 * @DoctrineAssert\UniqueEntity(fields={"day"})
 */
class Planning
{
    /**
     * @var integer $id
     *
     * @ORM\Id
     * @ORM\Column(name="id", type="smallint")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var datetime $day
     *
     * @ORM\Column(name="day", type="date", unique=true, nullable=false)
     * @Assert\NotNull()
     * @Assert\Date()
     */
    private $day;
</code></pre></div>
<p dir="auto">When i submit a form i have the following message :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Catchable Fatal Error: Object of class DateTime could not be converted to string in /Users/jf/Documents/aojf-workspace/lesroyaumes/vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php line 1074 "><pre class="notranslate"><code class="notranslate">Catchable Fatal Error: Object of class DateTime could not be converted to string in /Users/jf/Documents/aojf-workspace/lesroyaumes/vendor/doctrine-dbal/lib/Doctrine/DBAL/Connection.php line 1074 
</code></pre></div>
<p dir="auto">So i add the following lines in the UniqueEntityValidator.php file</p>
<p dir="auto">just after</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="if ($criteria[$fieldName] === null) {
    return true;
}"><pre class="notranslate"><code class="notranslate">if ($criteria[$fieldName] === null) {
    return true;
}
</code></pre></div>
<p dir="auto">this</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$fieldType = $class-&gt;getTypeOfField($fieldName);
if ($fieldType == Type::DATE)
{
    $criteria[$fieldName] = date_format($criteria[$fieldName], 'Y-m-d');
}"><pre class="notranslate"><code class="notranslate">$fieldType = $class-&gt;getTypeOfField($fieldName);
if ($fieldType == Type::DATE)
{
    $criteria[$fieldName] = date_format($criteria[$fieldName], 'Y-m-d');
}
</code></pre></div>
<p dir="auto">It works with Mysql database. But i can not test with others.<br>
Moreover, i do not know if 'Y-m-d' is generic and how i can do it generic for date and datetime.</p>
<p dir="auto">Running Symfony 2.4.3, I believe it's an issue in 2.4.4 as well</p>
<p dir="auto">If the Client is insulated, it tries to serialize() the data to pass to the Process. serialize() fails on UploadedFile.</p>
<p dir="auto"><a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Client.php#L145">https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Client.php#L145</a></p>
<p dir="auto">That line serializes the request, but if request contains UploadedFile it fails.</p>
<p dir="auto">Demonstration code:</p>
<p dir="auto">Have a form with a file upload field named "file" and submit button named "submit"</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$client = static::createClient($options, $server);
$client-&gt;insulate(true);
$crawler = $client-&gt;request(&quot;GET&quot;, $url);
$form = $crawler-&gt;selectButton(&quot;form[submit]&quot;)-&gt;form();
$form['form[file]']-&gt;upload(&quot;path/to/some/file&quot;);

$client-&gt;submit($form); // FAILS WITH BELOW TRACE"><pre class="notranslate"><code class="notranslate">$client = static::createClient($options, $server);
$client-&gt;insulate(true);
$crawler = $client-&gt;request("GET", $url);
$form = $crawler-&gt;selectButton("form[submit]")-&gt;form();
$form['form[file]']-&gt;upload("path/to/some/file");

$client-&gt;submit($form); // FAILS WITH BELOW TRACE
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="There was 1 error:

1) ...Test::test...
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

/.../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:145
/.../vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:368
/.../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:123
/.../vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:332
/.../...Test.php:74"><pre class="notranslate"><code class="notranslate">There was 1 error:

1) ...Test::test...
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed

/.../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:145
/.../vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:368
/.../vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Client.php:123
/.../vendor/symfony/symfony/src/Symfony/Component/BrowserKit/Client.php:332
/.../...Test.php:74
</code></pre></div>