Testing Doctrine2:使用YAML配置测试存储库类
我使用Doctrine2为我的symfony2项目提供了YAML配置。我不明白如何准确地将应用程序适应YAML设置 我的条令映射位于Testing Doctrine2:使用YAML配置测试存储库类,testing,symfony,doctrine-orm,Testing,Symfony,Doctrine Orm,我使用Doctrine2为我的symfony2项目提供了YAML配置。我不明白如何准确地将应用程序适应YAML设置 我的条令映射位于/path/to/My/bundle/Resources/config/doctrine/IpRange.orm.yml 运行PHPUnit时,我得到错误: 条令\ORM\Mapping\MappingException:找不到类“Yitznewton\FreermsBundle\Entity\IpRange”的名为“Yitznewton.FreermsBundle
/path/to/My/bundle/Resources/config/doctrine/IpRange.orm.yml
运行PHPUnit时,我得到错误:
条令\ORM\Mapping\MappingException:找不到类“Yitznewton\FreermsBundle\Entity\IpRange”的名为“Yitznewton.FreermsBundle.Entity.IpRange.ORM.yml”的映射文件
听起来我需要配置测试装备来使用symfony文件命名约定,但我不知道如何做到这一点
使用symfony-standard.git签出到v2.0.7
这是我的测试:
<?php
namespace Yitznewton\FreermsBundle\Tests\Utility;
use Doctrine\Tests\OrmTestCase;
use Doctrine\ORM\Mapping\Driver\DriverChain;
use Doctrine\ORM\Mapping\Driver\YamlDriver;
use Yitznewton\FreermsBundle\Entity\IpRange;
use Yitznewton\FreermsBundle\Entity\IpRangeRepository;
class IpRangeRepositoryTest extends OrmTestCase
{
private $_em;
protected function setup()
{
// FIXME: make this path relative
$metadataDriver = new YamlDriver('/var/www/symfony_2/src/Yitznewton/FreermsBundle/Resources/config/doctrine');
$metadataDriver->setFileExtension('.orm.yml');
$this->_em = $this->_getTestEntityManager();
$this->_em->getConfiguration()
->setMetadataDriverImpl($metadataDriver);
$this->_em->getConfiguration()->setEntityNamespaces(array(
'FreermsBundle' => 'Yitznewton\\FreermsBundle\\Entity'));
}
protected function getRepository()
{
return $this->_em->getRepository('FreermsBundle:IpRange');
}
public function testFindIntersecting_RangeWithin_ReturnsIpRange()
{
$ipRange = new IpRange();
$ipRange->setStartIp('192.150.1.1');
$ipRange->setEndIp('192.160.1.1');
$this->assertEquals(1, count($this->getRepository()
->findIntersecting($ipRange)),
'some message');
}
setFileExtension('.orm.yml');
$this->_em=$this->_getestentitymanager();
$this->\u em->getConfiguration()
->setMetadataDriverImpl($metadataDriver);
$this->\u em->getConfiguration()->setEntityNamespaces(数组(
‘FreermsBundle’=>‘Yitznewton\\FreermsBundle\\Entity’);
}
受保护的函数getRepository()
{
返回$this->_em->getRepository('FreermsBundle:IpRange');
}
公共函数testFindIntersecting_Range在_ReturnsIpRange()内
{
$ipRange=新ipRange();
$ipRange->setStartIp('192.150.1.1');
$ipRange->setEndIp('192.160.1.1');
$this->assertEquals(1,count)($this->getRepository()
->findIntersecting($ipRange)),
“一些信息”);
}
再看看symfony文档,与存储库类的单元测试相比,使用实时测试数据库进行集成测试似乎更可取。也就是说,不支持Stubing EntityManager