Skip to content

[FrameworkBundle] added a check in Client to only shutdown the kernel #742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

[FrameworkBundle] added a check in Client to only shutdown the kernel #742

wants to merge 1 commit into from

Conversation

danielholmes
Copy link
Contributor

I had a problem with the Beta1 version with my WebTestCase tests. The pattern i used was to create a client in my test setUp, then populate the database with fixtures, then run my tests. e.g.:

protected function setUp()
{
    $this->client = $this->createClient();
    $fixtures = array(
        new UserDataFixture()
    );
    $this->populateWithTestDatabase($this->client, $fixtures);
}

When the actual test ran the database wasn't populated, the container in my controller was a different instance than the container i used to populate the database in the test case. The issue was that the FrameworkBundle Client shuts down the kernel before each request, meaning my in memory sqlite database had disappeared. Another user encountered this as well: http://groups.google.com/group/symfony-users/browse_thread/thread/892d58f7571b3f31#.

The solution I've added is to only shut down the kernel if a request has previously been made. Also in the current state most functional tests will result in the kernel booting twice at the start of a test

@ghost ghost assigned fabpot May 3, 2011
@fabpot
Copy link
Member

fabpot commented May 3, 2011

I don't like this patch as it feels "unclean". Why not using a SQLite DB in a file?

@Chekote
Copy link

Chekote commented May 3, 2011

I use SQLite specifically because it runs in memory, I have a significant amount of tests, and the performance increase of an in-memory database for testing is very helpful.

However, I don't believe this problem is directly related to the Client shutting down the Kernel. My tests using in-memory SQLite worked fine even with the Client shutting down the Kernel. Something else has happened recently that causes the SQLite database to get destroyed.

The last commit I worked from where the Client did shutdown the Kernel, but the SQLite database was not reset was d873f21

@Chekote
Copy link

Chekote commented May 3, 2011

If you don't like this method, can we pass a parameter to the doRequest method to specify whether or not the Kernel should be shutdown?

@danielholmes
Copy link
Contributor Author

@fabpot
Yea I can understand the point of view that it feels unclean. If it's left as is, there's still the inefficiency of the kernel booting twice in a test:

WebTestCase
public function createClient(array $options = array(), array $server = array())
{
$this->kernel = $this->createKernel($options);
$this->kernel->boot();

FrameworkBundle\Client:
protected function doRequest($request)
{
$this->kernel->shutdown();
$this->kernel->handle($request); // Implicit boot here done inside the kernel

The minimum to solve that is to remove the boot from createClient, however it's needed in order to get the test client. I can't think of any good solution to that at the moment and i think it's mainly a performance consideration, so feel free to close the PR if you don't think it matters.

@Chekote
The alternative I've been using is to add test.client.class: MyProject\Test\Client in my config and do whatever I need in the doRequest

@lsmith77
Copy link
Contributor

lsmith77 commented May 7, 2011

In-memory is obviously quite fast, but I think you are going to run into issues in many scenarios with your approach, where tests will fail like you explained above or will start leaking. Also the more complex your schema and fixtures the longer it will take to reinitialize your db.

So I recommend this Bundle:
https://github.com/liip/FunctionalTestBundle

Basically when using SQLite it can cache the SQLite db files with your schema+fixtures installed and reuse them instead of having to set things up in memory repeatedly.

@danielholmes
Copy link
Contributor Author

That's a great bundle, it made a big different for me. With the caching of a file based db, my functional test suite is about 30% quicker than using an in memory db. That difference will just get bigger as well as the project keeps growing, thanks!

@Chekote
Copy link

Chekote commented May 10, 2011

Given the existence of FunctionalTestBundle, do you want to close this pull request?

@fabpot
Copy link
Member

fabpot commented May 11, 2011

merged

fabpot added a commit that referenced this pull request Sep 16, 2013
This PR was merged into the 2.3 branch.

Discussion
----------

fixed bytes conversion when used on 32-bits systems

| Q             | A
| ------------- | ---
| Bug fix?      | yes (on 32-bits systems)
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #8977
| License       | MIT
| Doc PR        | n/a

This PR reverts #7413 and #742, which does not work well when a number is big (3Go for instance) and the machine is 32bits.

Commits
-------

b3ae29d fixed bytes conversion when used on 32-bits systems
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants