小编Jan*_* CL的帖子

如何在Symfony 3中模拟'find'方法

我试图模仿它的find方法EntityRepository,以便测试不会在数据库中查找数据,但它似乎不起作用.这是setUp测试类的方法

public function setUp()
{
    parent::setUp();

    $this->client = static::createClient();
    $this->peopleManager = $this->getMockBuilder(PeopleManager::class)
        ->setMethods(['createPerson','peopleUpdate', 'peopleDelete', 'peopleRead'])
        ->disableOriginalConstructor()
        ->getMock();

   $this->repository = $this->getMockBuilder(EntityRepository::class)
       ->disableOriginalConstructor()
       ->getMock();

   $this->em = $this->getMockBuilder(EntityManager::class)
       ->disableOriginalConstructor()
       ->getMock(); 
}
Run Code Online (Sandbox Code Playgroud)

这是我们调用find函数的方法

public function updatePersonAction($id, Request $request)
{
    $repository = $this->getDoctrine()->getRepository('GeneralBundle:People');
    $person= $repository->find($id);
    if($person)
    {
        $data = $request->request->get('array');
        $createdPeople = array();
        $UpdatedPerson = "";
        foreach($data as $content)
        {
            $prueba = $this->get('people.manager');
            $UpdatedPerson = $prueba->peopleUpdate(
                $person,
                $content['name'],
                $content['surname'],
                $content['secondSurname'],
                $content['nationality'],
                $content['birthday'],
                $content['identityCard'],
                $content['identityCardType']
            );
            array_push($createdPeople, $person);
        }
        $serializedEntity …
Run Code Online (Sandbox Code Playgroud)

php testing mocking symfony doctrine-orm

1
推荐指数
1
解决办法
1173
查看次数

标签 统计

doctrine-orm ×1

mocking ×1

php ×1

symfony ×1

testing ×1