Skip to content

Mocking same method with different "with" and different "return" throw an exception #4398

Open
@oleg-andreyev

Description

@oleg-andreyev
Q A
PHPUnit version 9.2.6
PHP version 7.4.8
Installation Method Composer

Summary

Mocking same method with different "with" and different "return"

Current behavior

Expectation failed for method name is "getRepository" when invoked zero or more times
Parameter 0 for invocation Doctrine\ORM\EntityManager::getRepository('Op\AppBundle\Entity\Order') does not match expected value.
Failed asserting that two strings are equal.
Expected :'Op\AppBundle\Entity\Customer'
Actual   :'Op\AppBundle\Entity\Order'

How to reproduce

        $this->em
            ->method('getRepository')
            ->with(Customer::class)
            ->willReturn($this->customerRepository);

        $this->em
            ->method('getRepository')
            ->with(Order::class)
            ->willReturn($this->orderRepository);
$this->em->getRepository(Order::class)->findOneByOrderId($id);

image

Expected behavior

If "matcher" did not throw an exception on the second "match" (invoke), we should not throw an exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions