I try to only go one layer deep with my mock objects. Since I'm trying to test
the class at hand in isolation I have no reason to go any deeper. This usually
means disabling the constructor…
$mock = $this->getMockBuilder('myClass')
->disableOriginalConstructor()
->getMock();
On the occasion I need a dependency to return one of its dependencies I'll just
mock that getter method. Typically this is an indication that my design needs a
bit of work.
--
Kris Wallsmith | Release Manager
[email protected]
Portland, Oregon USA
http://twitter.com/kriswallsmith
On Oct 5, 2010, at 3:06 PM, Jordi Boggiano wrote:
> On 05.10.2010 19:08, Lukas Kahwe Smith wrote:
>> I didnt make it clear, but I specifically did not want to automate the
>> method mocking, just the objects themselves. Now in terms of adding
>> expects() calls, for shared services it should be easy to just get the
>> service and add the expects() call. For non shared, it would be cool to be
>> able to have some way to define a (set of ) instances to use next maybe.
>
> Maybe something like (throwing random ideas):
>
> $services = $this->getServiceMock('router');
>
> then services would be:
>
> array(
> 'router' => RouterMock,
> 'router.loader' => RouterLoaderMock,
> )
>
> i.e. returning you the dependencies that were injected as well as the
> service you requested.
>
> or:
>
> array(
> 'service' => RouterMock,
> 'args' => array(
> RouterLoaderMock,
> stuff,
> array('param', 'param')
> )
> )
>
> i.e. returning all the constructor arguments + the requested service.
>
> Also other random thought: maybe the DIC should have an option to
> disable service sharing, so that when doing unit testing you could tell
> it to stop sharing, and it'd just create new instances every time. You
> probably don't want that for integration testing since shared services
> are probably key functionality in the grand scale of things, but for
> unit testing it could make it faster than instanciating a new DIC every
> time?
>
> Cheers
>
> --
> Jordi Boggiano
> @seldaek :: http://seld.be/
>
> --
> If you want to report a vulnerability issue on symfony, please send it to
> security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" 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/symfony-devs?hl=en
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" 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/symfony-devs?hl=en