phpspec / prophecy

Highly opinionated mocking framework for PHP 5.3+
MIT License
8.53k stars 242 forks source link

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

Open aitboudad opened 10 years ago

aitboudad commented 10 years ago
    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 commented 10 years ago

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 commented 10 years ago
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 commented 10 years ago

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

stof commented 10 years ago

Actually, could you try https://github.com/phpspec/prophecy/issues/54#issuecomment-26619535 ?

aitboudad commented 10 years ago

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 commented 10 years ago

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 commented 8 years ago

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