This question is nearly a year old, no further discussion required at this end.

-- 
Phil Bennett
http://www.happyaccidents.me

On 10 June 2014 at 16:11:00, Marco Pivetta ([email protected]) wrote:

Mocking a query is like replacing an entire piece of code to be executed, it is 
not the replacement of a dependency.

You are effectively missing a part of the codebase to be tested here.

Verifying that a query is "correctly assembled" is as functionally meaningful 
as "has no compile errors". Your query may be perfectly put together, but it 
could actually not do anything useful at all.

Marco Pivetta

http://twitter.com/Ocramius     

http://ocramius.github.com/


On 10 June 2014 16:57, Marco Jantke <[email protected]> wrote:
Why dont use the AbstractQuery for mocking purposes then? Works fine.

Am Montag, 8. Juli 2013 16:57:15 UTC+2 schrieb Phil Bennett:
@Marco It's a simplistic expectation and return testing layer, I don't need a 
mock of a specific query, I just need an instance of the query object to be 
returned by another object, no interaction with it whatsoever so anything else 
would be overkill.

On 8 Jul 2013, at 15:50, Marco Pivetta <[email protected]> wrote:

@Phil as said, mocking queries does not really make sense, as queries are the 
equivalent of `eval`-ed code, just with a different engine.


If you want to keep doctrine out of the way, you should instead insulate code 
containing DQL into custom repository (and interfaces for them) and then mock 
at that level. Testing the repository logic most probably requires you to work 
with data fixtures

Marco Pivetta

http://twitter.com/Ocramius     

http://ocramius.github.com/


On 8 July 2013 16:17, Phil Bennett <[email protected]> wrote:
I just want to mock everything away and properly unit test the models without 
touching Doctrine directly so the interface would do that job.

On 8 Jul 2013, at 15:14, Marco Pivetta <[email protected]> wrote:

There is no real way to mock a query object like that to be honest. The only 
thing you *could* do is checking the generated SQL, but a query is just code 
evaluated by an SQL backend (in my opinion.

I think the idea of mocking a query is per-se wrong.



Marco Pivetta

http://twitter.com/Ocramius     

http://ocramius.github.com/


On 8 February 2011 16:49, Alex Burdenko <[email protected]> wrote:
Hello all. I have some very specific problems with mocking while unit
testing using the Doctrine 2 Query class. My thought was to use
PHPUnit to Mock the Query.execute() method that is used throughout my
code. I've successfully replaced the EntityManager, EntityRepository,
and QueryBuilder classes with mock objects in the Zend_Registry (oh
yeah, I'm using this with the Zend Framework). But, the Query class is
marked final and is therefore unmockable. PHPUnit throws the following

PHPUnit_Framework_Exception: Class "Doctrine\ORM\Query" is declared
"final" and cannot be mocked.

The Query class mock is also missing from GitHub (https://github.com/
doctrine/doctrine2/tree/master/tests/Doctrine/Tests/ORM) so I don't
know if this was attempted by the core Doctrine team. I see no way
around this other than removing the final keyword from the Query class
but I find modifying the core library unappealing. Here's an example
of the code I'm trying to mock.

$queryBuilder
                ->select('a')
                ->from('Model', 'm');


$query = $queryBuilder->getQuery();
$results = $query->execute();


The last line is the problem. Is there a clean way to mock this? What
are the alternatives? Thanks in advance for your help.

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].

For more options, visit this group at 
http://groups.google.com/group/doctrine-user?hl=en.



--
You received this message because you are subscribed to a topic in the Google 
Groups "doctrine-user" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/doctrine-user/S7s6UvKz4bY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].

To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
You received this message because you are subscribed to a topic in the Google 
Groups "doctrine-user" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/doctrine-user/S7s6UvKz4bY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].
To post to this group, send email to [email protected].

Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google 
Groups "doctrine-user" group.
To unsubscribe from this topic, visit 
https://groups.google.com/d/topic/doctrine-user/S7s6UvKz4bY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to 
[email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to