With the in memory db, I still have the problem of multi request tests
where the db wont be present across both. Have you run in to this
problem? e.g.:

    $crawler = $this->client->request('GET', '/contact');  // Request
1, container created
    $form = $crawler->filter('#user-form input.button')-
>form($params);
    $this->client->submit($form);   // Request 2, kernel shutdown in
Client->doRequest so db lost


To solve this you can add this parameter in your config:

    test.client.class: MyProject\Test\Client


Then within the MyProject\Test\Client I've been using this to keep
that in memory connection:

    protected function doRequest($request)
    {
        if ($this->hasRequest)
        {
            $container = $this->kernel->getContainer();
            $conn = $container-
>get('doctrine.dbal.default_connection');

            $this->kernel->shutdown();
            $this->kernel->boot();

            $newContainer = $this->kernel->getContainer();
            $newContainer->set('doctrine.dbal.default_connection',
$conn);
        }
        else
        {
            $this->hasRequest = true;
        }

        $response = $this->kernel->handle($request);

        return $response;
    }



On May 4, 1:43 am, Donald <chekot...@gmail.com> wrote:
> Looks like other people are experiencing this problem, and
> unfortunately Fabien doesn't seem to think it's a real issue...
>
> https://github.com/symfony/symfony/pull/742#issuecomment-1094468
>
> On May 3, 10:40 am, Donald <chekot...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hi Daniel,
>
> > Thanks for the info. Although commenting out that line does resolve
> > the problem, I think there's something going on a little deeper.
>
> > My tests actually passed after this commit, so something has changed
> > since then. Maybe something in the way the kernel actually carries out
> > the shutdown / reboot process...
>
> > On May 2, 6:28 pm, danielholmes <dan...@creatio.com.au> wrote:
>
> > > Hi Donald,
>
> > > I'm glad I wasn't the only one having this problem. Thanks for
> > > mentioning the spl_object_hash; I hadn't seen it before.
>
> > > Using that, I found they are actually referring to different
> > > containers. I tracked the problem down to this commit:
>
> > >https://github.com/symfony/symfony/commit/91602dfef4051c400b12cf8f13f...
>
> > > Specifically in the FrameworkBundle\Client.php class:
>
> > >     protected function doRequest($request)
> > >     {
> > >         $this->kernel->shutdown();
>
> > >         return $this->kernel->handle($request);
> > >     }
>
> > > If you comment out the $this->kernel->shutdown(); then the initial
> > > test will work correctly (assuming you've warmed your cache in the
> > > test environment - php app/console cache:warmup --env=test).
>
> > > Most of my tests now pass with that removed (the others im working
> > > through, look to mostly be url changes though), but I'm not sure of
> > > the other implications
>
> > > On May 3, 7:20 am, Donald <chekot...@gmail.com> wrote:
>
> > > > With further testiing, I've verified the following:
>
> > > > 1. The Controller see's no tables at all. Printing the results of 
> > > > $em->getConnection()->getSchemaManager()->createSchema() in
>
> > > > testSomething() outputs the expected schema, whereas running the same
> > > > line in the action for /things/1.html outputs an empty schema.
>
> > > > 2. The Controller and Test classes *are* using different connections.
> > > > Printing the results of spl_object_hash($em->getConnection()) in both
> > > > classes results in a different hash.
>
> > > > I'll continue to investigate further, but I'd still appreciate some
> > > > input if anyone has any helpful pointers.
>
> > > > Thanks.
>
> > > > On May 2, 3:40 pm, Donald <chekot...@gmail.com> wrote:
>
> > > > > I'm in the middle of upgrading my project to use Symfony 2 Beta 1,
> > > > > from it's current version of PR11, and I've run into a problem with
> > > > > the tests that I can't work out.
>
> > > > > I use pdo_sqlite for my tests, and create the schema in the setup
> > > > > method of each test. This would work fine in PR11, but in Beta 1,
> > > > > something has changed where the Client doesn't see the database that
> > > > > my Test created.
>
> > > > > Here's an example test:
>
> > > > > class MyTest extends WebTestCase {
>
> > > > >   protected function setUp() {
> > > > >     $this->client = $this->createClient();
> > > > >     $this->client->followRedirects(false);
>
> > > > >     $this->container = $this->kernel->getContainer();
>
> > > > >     $em = $this->container->get('doctrine.orm.entity_manager');
>
> > > > >     $tool = new SchemaTool($em);
> > > > >     $metaData = $em->getMetaDataFactory()->getAllMetaData();
> > > > >     $tool->createSchema($metaData);
>
> > > > >     $thing1 = new Thing();
> > > > >     $thing1->name = 'Bob';
>
> > > > >     $em->persist($thing1);
> > > > >     $em->flush();
> > > > >   }
>
> > > > >   public function testSomething() {
> > > > >     // just to demonstrate that the database and object *does* exist,
> > > > > this works:
> > > > >     $em = $this->container->get('doctrine.orm.entity_manager');
> > > > >     echo get_class($em->find('MyBundle:Thing', 1));
>
> > > > >     // This however, fails (assuming that the action at this URL will
> > > > > attempt to load Thing1)
> > > > >     $this->client->request('GET', sprintf('/things/1.html'));
> > > > >     $response = $this->client->getResponse();
>
> > > > >     // Response will be a stack trace stating "General error: 1 no
> > > > > such table: thing"
> > > > >     print_r($response);
> > > > >   }
>
> > > > > }
>
> > > > > I've updated all my config files with the new cleaner dbal
> > > > > configuration style, and as demonstrated by the fact that the fixtures
> > > > > and the first couple of lines of this test works, it is configured
> > > > > correctly.
>
> > > > > Can anyone point me in the direction of what changed to break this? It
> > > > > seems as if the MyTest and Client instances are not working from the
> > > > > same EntityManager and/or Connection.
>
> > > > > Thanks,
>
> > > > > Donald

-- 
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 users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to