Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8660493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:15:57+00:00 2026-06-12T16:15:57+00:00

I have an issue with my Entity Manager in phpunit. This is my test

  • 0

I have an issue with my Entity Manager in phpunit.

This is my test :

public function testValidChangeEmail()
{
    $client = self::createAuthClient('user','password');

    $crawler = $client->request('GET', '/user/edit/30');
    $crawler = $client->submit($crawler->selectButton('submit')->form(array(
        'form[email]' => 'new@email.com',
    )));

    /*
     * With this em, this work perfectly 
     * $em = $client->getContainer()->get('doctrine.orm.entity_manager');
     */

    $user = self::$em->getRepository('MyBundle:User')->findUser('new@email.com');

    die(var_dump($user->getEmail()));
}

and this is my WebTestCase which extends original WebTestCase :

class WebTestCase extends BaseWebTestCase
{
    static protected $container;
    static protected $em;

    static protected function createClient(array $options = array(), array $server = array())
    {
        $client = parent::createClient($options, $server);
        self::$em = $client->getContainer()->get('doctrine.orm.entity_manager');
        self::$container = $client->getContainer();

        return $client;
    }

    protected function createAuthClient($user, $pass)
    {
        return self::createClient(array(), array(
            'PHP_AUTH_USER' => $user,
            'PHP_AUTH_PW'   => $pass,
        ));
    }

As you can see, I replace the self::$em when I created my client.

My issue :

In my test, the die() give me the old email and not the new email (new@email.com) which has registered in the test. However in my database, I have the new@email.com correctly saved.

When I retrieve my user in the database, I use sefl::$em. If I use the $em in comments, I retrieve the right new email.

I don’t understand why in my WebTestCase, I can access to the new Entity Manager…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:15:58+00:00Added an answer on June 12, 2026 at 4:15 pm

    You can’t access to the new entity manager because Symfony’s client class shutdown’s kernel before each request, which means that it erase whole service container and build it again from scratch.

    So, after SECOND request you get very different entity manager than one you have in your own WebTestCase class. (I said after second because client shutdown’s kernel only if any request has been already performed)

    The question is – do you really need the same entity manafer in your WebTestCase class? Actually, you may want use the same entity manager because you want let say get controll over transaction between requests. But in this case you should create your own test client class extended symfony’s one and there define static connection or entity manager, and put it into container before every request.

    Look at example:
    http://alexandre-salome.fr/blog/Symfony2-Isolation-Of-Tests

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue in entity framework code first, three table in database as
I have an issue about Entity Framework 4 CTP 5, which I realize LINQ
I have an issue with deletion in Entity Framework. In short, EF explicitly tries
I have issue with: <form:checkboxes path=roles cssClass=checkbox items=${roleSelections} /> If previous line is used
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR
Share your ideas please! I have issue to check the folder and convert a
Have an issue with marshall and unmarshall readers and writers. So here it is.
I have an issue with jquery and history.back(): I got a link: <a href=#
I have an issue of alphabetically sorting the contacts picked from the address book

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.