Hi Mauricio

For unit tests standard PHPUnit_Framework_TestCase should be all you'd need.
You might also want to check out my slides on the topic -
http://www.slideshare.net/avalanche123/clean-code-5609451
WebTestCase can be used to test any service that is supposed to be wired in
the container.
the reason you have to get container after the client is created is because
it gets reloaded on every client request,
to simulate real remote communication and to clean up any state that might
have been left out.
Therefore, don't worry about calling getContainer too many times - its the
right thing to do in order to interact with a proper instance of it.

On a side note, if you're re-creating the container more than twice might
mean you're testing too much.

<http://www.slideshare.net/avalanche123/clean-code-5609451>Best,
Bulat

On Fri, Jan 14, 2011 at 11:55 AM, Mauricio Morales <[email protected]>wrote:

> Hi Ryan, thanks for replying.
>
> You made me think and you're right, even if I need to test the domain
> behavior of my application I shouldn't test the persistance, which is
> supposed to be tested by Doctrine itself before getting included to
> Symfony2. Maybe as a sanity doble check I should run Doctrine-ODM
> tests everytime I update the framework in my app.
>
> However, how are you guys writing Unit Tests (not for controllers/
> actions), is it extending from WebTestCase too?
>
> Cheers!,
>
> On Jan 14, 12:41 pm, ryan weaver <[email protected]> wrote:
> > Hey Mauricio-
> >
> > If the unit test being written is for a document that happens to be
> > persisted to mongodb, your tests for that document class should only test
> > the functionality of the class itself - which is independent of
> persistence.
> > In other words, to give a trivial example, you can test the setName()
> method
> > on a class without ever dealing with persistence by simply checking that
> the
> > name property is set. Persistence is external to the document itself.
> >
> > If I'm misunderstanding you, just post some example code.
> >
> > Thanks
> >
> > @weaverryan
> > On Jan 14, 2011 4:44 AM, "Mauricio Morales" <[email protected]>
> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > Hello guys,
> >
> > > I've seen there is a WebTestCase class under Symfony\Bundle
> > > \FrameworkBundle\Test which is intended to be used for controller's
> > > actions tests. I'm using MongoDB and I've been writing unit tests for
> > > objects that are mapped to MongoDB documents. I've seen that MongoDB
> > > itself has Doctrine\ODM\MongoDB\Tests\BaseTest class that can be used
> > > for that.
> >
> > > What I've found is that we need a Kernel instance in order to get the
> > > proper classes/drivers used by the ODM (also paths to the hydrators/
> > > proxies cache folder, etc.).
> >
> > > I managed to do it by extending WebTestCase and using something like:
> >
> > > public function setUp()
> > > {
> > > $this->createClient();
> > > $this->dm = $this->kernel->getContainer()-
> > >>get('doctrine.odm.mongodb.document_manager');
> > > }
> >
> > > public function tearDown()
> > > {
> > > if ($this->dm) {
> > > foreach ($this->dm->getDocumentDatabases() as $db) {
> > > foreach ($db->listCollections() as $collection) {
> > > $collection->drop();
> > > }
> > > }
> > > $this->dm->getConnection()->close();
> > > }
> > > }
> >
> > > But this solution is kind of dirty, rather I'd like to have a
> > > UnitTestCase class. My question is, how would you write a test for
> > > it?, Is there any we can improve the framework in that sense?, please
> > > give me some ideas and I work on the fix.
> >
> > > Mauricio.
> >
> > > --
> > > 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]<symfony-devs%[email protected]>
> <symfony-devs%2Bunsubscribe@google groups.com>
> > > 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]<symfony-devs%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>



-- 
*Bulat Shakirzyanov* | Software Alchemist

*a: *about.me/avalanche123
*e:* [email protected]

-- 
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

Reply via email to