Symfony2无法创建具有日期的灯具

时间:2015-12-30 13:26:51

标签: php symfony doctrine-orm fixtures

我尝试在单元测试中使用灯具。 DB - pdo_sqlite,Doctrine2 我有课: 使用Doctrine \ ORM \ Mapping作为ORM;

/**
 * Statspg
 * @ORM\Table(name="statsPG")
 */
class Statspg
{
    /**
     * @var \DateTime
     *
     * @ORM\Id
     * @ORM\Column(name="`date`", type="datetime")
     */
    private $date;

    /**
     * @var string
     *
     * @ORM\Id
     * @ORM\Column(name="groupid", type="string", length=64)
     */
    private $groupid;

和fixture yaml文件:

Acme\StatisticsBundle\Entity\Statspg:
  Stat0:
     date: <(new \DateTime('2014-02-02'))>
     groupid: testGroupId0

当我运行测试设置纹理时,我收到一个错误:

  

类DateTime的对象无法转换为字符串

     

/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1413   /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1226   /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:915   /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1683   /vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1639   /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:579   /vendor/nelmio/alice/src/Nelmio/Alice/ORM/Doctrine.php:37   /vendor/nelmio/alice/src/Nelmio/Alice/Fixtures.php:130   /vendor/nelmio/alice/src/Nelmio/Alice/Fixtures.php:104   /vendor/nelmio/alice/src/Nelmio/Alice/Fixtures.php:57   /vendor/liip/functional-test-bundle/Test/WebTestCase.php:458   /src/Acme/AcmeBundle/Tests/Controller/Rest/GroupControllerTest.php:14

我做错了什么?

更新

查找Doctrine 2 ORM DateTime field in identifier

现在我明白问题是主键是\ DateTime

0 个答案:

没有答案