how to (php)spec when entity change some values, then my entitymanager not working as expected

395 views
Skip to first unread message

Silviu Constantin Voicu

unread,
Sep 2, 2013, 12:20:21 PM9/2/13
to phpsp...@googlegroups.com
Hello,

My title is not very descriptive, but I hope, that after I will explain my problem, I would get some help.

I describe a symfony2 controller, and in my let function I have something like that:

       $container->get('doctrine')->willReturn($doctrine);
    
       $doctrine->getManager()->willReturn($entityManager);

       $entityManager->getRepository(Argument::any())->willReturn($repository);


among others.
Now when in the function where I was specking the behaviour that when form is valid it will save my object in the database,
I have among other, something like this:

        $entityManager->persist($reader)->shouldBeCalled();

        $entityManager->flush()->shouldBeCalled();

And now it' ok, but if either in my spec I add this line  $reader->setSalt(Argument::any());   or in my code this line $reader->setSalt(md5(time()));

then when I run my spec I got this kind of  error, in the
both cases
    
       method call:
          Double\Doctrine\ORM\EntityManager\P205362297->persist(BddSBP\ReaderBundle\Entity\Reader:00000000250f842f00000000098356d6)
        was not expected.
        Expected calls are:
          - getRepository(*)
          - persist(exact(BddSBP\ReaderBundle\Entity\Reader:00000000250f838200000000098356d6))
          - flush()

So basically, if change my entity object, then my spec will be broken.

Thank you.



Silviu Constantin Voicu

unread,
Sep 6, 2013, 7:19:48 AM9/6/13
to phpsp...@googlegroups.com
I found a solution like in this my own gist https://gist.github.com/silviuvoicu/6462509
Reply all
Reply to author
Forward
0 new messages