Skip to content

PHPSpec does not find the right FQCN in some cases to generate doubles #1429

@Nek-

Description

@Nek-

I tried hard to debug this one (many times), but I have really no idea why I get it... Tried many versions of phpspec (from 6 to last). I can't stop thinking the issue is something stupid I missed, but well, I quadruple-checked everything... So here is my issue, and sorry in advance if it's stupid.

Consider the following spec:

namespace spec\App\MainApi\Domain\Player\Controller;

use App\Exception\DomainException;
use App\MainApi\Domain\Player\Controller\ConfirmationController;
use App\MainApi\Domain\Player\Data\PlayerRepository;
use Doctrine\ORM\EntityManagerInterface;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Form\FormFactoryInterface;

class ConfirmationControllerSpec extends ObjectBehavior
{
    public function let(FormInterface $form, FormFactoryInterface $formFactory, PlayerRepository $playerRepository, EntityManagerInterface $entityManager)
    {
        $formFactory->createNamed(Argument::cetera())->willReturn($form);
        $this->beConstructedWith($formFactory, $playerRepository, $entityManager);
    }

    public function it_is_initializable()
    {
        $this->shouldHaveType(ConfirmationController::class);
    }
}

I end up with the following error, and I have no idea why:

image

I have a fix for it, but this code should works!

Changing the let method to this fixes the problem:

    public function let(FormInterface $form, FormFactoryInterface $formFactory, PlayerRepository $playerRepository, EntityManagerInterface $entityManager)
    {
        $entityManager->beADoubleOf(EntityManagerInterface::class);
        $formFactory->createNamed(Argument::cetera())->willReturn($form);
        $this->beConstructedWith($formFactory, $playerRepository, $entityManager);
    }

Do you have any idea why I have this issue? (I have this issue with some other interfaces/classes, but it seems connected to dependencies... I have no issues with classes living in the src folder)

PHP Version:

PHP 8.0.8 (cli) (built: Mar  3 2022 14:51:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions