Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Nek- opened this issue Apr 13, 2022 · 1 comment
Open

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

Nek- opened this issue Apr 13, 2022 · 1 comment

Comments

@Nek-
Copy link

Nek- commented Apr 13, 2022

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
@Nek- Nek- changed the title PHPSpec does not find the right class PHPSpec does not find the right FQCN in some cases Apr 13, 2022
@Nek- Nek- changed the title PHPSpec does not find the right FQCN in some cases PHPSpec does not find the right FQCN in some cases to generate doubles Apr 13, 2022
@gquemener
Copy link
Contributor

Any update on this?

2 things from first sight:

  • debugging the collaborator generation, and especially how the argument fqcn is resolved, would bring light to the root of the issue. I can give a hand with that, if the issue is still confirmed nowadays.
  • you should not mock what you don't own (that point is opinionated, and would mean choosing a different testing strategy for "testing controller")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants