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

Getting error when stubbing Doctrine\ORM\Query\Filter\SQLFilter #92

Open
aitboudad opened this issue Mar 14, 2014 · 7 comments
Open

Getting error when stubbing Doctrine\ORM\Query\Filter\SQLFilter #92

aitboudad opened this issue Mar 14, 2014 · 7 comments

Comments

@aitboudad
Copy link

    function let(EntityManager $em, FilterCollection $filters, SQLFilter $filter)
    {
        $this->beConstructedWith($em);
        $filters->enable('status_filter')->willReturn($filter);
    }
PHP Fatal error:  Cannot override final method Doctrine\ORM\Query\Filter\SQLFilter::__construct() in /home/a-aitboudad/www/isobar/mixa/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(48) : eval()'d code on line 2
@stof
Copy link
Member

stof commented Mar 14, 2014

Can you tell us the version of Prophecy you are using ?
When using composer to manage your dependencies, the best way is to paste the output of composer show -i phpspec/prophecy

@aitboudad
Copy link
Author

name     : phpspec/prophecy
descrip. : Highly opinionated mocking framework for PHP 5.3+
keywords : Double, Dummy, fake, mock, spy, stub
versions : * 1.1.2
type     : library
license  : MIT
source   : [git] https://github.com/phpspec/prophecy.git 976a65af02a2a0e17ce6c949f7b43437205628bb
dist     : [zip] https://api.github.com/repos/phpspec/prophecy/zipball/976a65af02a2a0e17ce6c949f7b43437205628bb 976a65af02a2a0e17ce6c949f7b43437205628bb
names    : phpspec/prophecy

@aitboudad
Copy link
Author

@stof I get the same error with the dev-master version.

@stof
Copy link
Member

stof commented Mar 14, 2014

Actually, could you try #54 (comment) ?

@aitboudad
Copy link
Author

After doing some debug, it only work when I comment this line DisableConstructorPatch#L45 (#30)
As I think it shouldn't add __construct method if it's final (already ignored in ClassMirror#L111)

What do you propose to solve this issue ?

@docteurklein
Copy link
Contributor

Could it be resolved by leting the classMirror looking at private final methods too ? Actually it doesn't verify if final because it's not public.

@koemeet
Copy link

koemeet commented Feb 3, 2016

Is there a good solution for this? I too have to stub a SQLFilter. I am quite new to PHPSpec, but I cannot unit test my listener properly without having my filter. I have to test that it calls SQLFilter::setParameter() correctly.

This is the code I use:

function it_sets_workspace_parameter_on_workspace_filter_when_there_is_a_workspace(
    FilterControllerEvent $event,
    $entityManager,
    $workspaceContext,
    WorkspaceInterface $workspace,
    FilterCollection $filterCollection,
    WorkspaceFilter $workspaceFilter
) {
    $workspaceFilter->beConstructedWith([$entityManager]);

    $event->getRequestType()->willReturn(HttpKernelInterface::MASTER_REQUEST);

    $workspaceContext->getWorkspace()
        ->shouldBeCalled()
        ->willReturn($workspace)
    ;

    $entityManager->getFilters()
        ->shouldBeCalled()
        ->willReturn($filterCollection)
    ;

    $filterCollection->getFilter('workspace')
        ->shouldBeCalled()
        ->willReturn($workspaceFilter)
    ;

    $workspace->getId()
        ->shouldBeCalled()
        ->willReturn(42)
    ;

    $workspaceFilter->setParameter('workspace_id', 42)
        ->shouldBeCalled()
    ;

    $this->onKernelController($event);
}

No matter what I try, I keep getting:

PHP Fatal error:  Cannot override final method Doctrine\ORM\Query\Filter\SQLFilter::__construct() in /Users/steffen/Development/shopblender/vendor/phpspec/prophecy/src/Prophecy/Doubler/Generator/ClassCreator.php(49) : eval()'d code on line 2

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

No branches or pull requests

5 participants