Skip to content

Add note about calling parent::setUp() #2

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
jdietrch opened this issue Jan 26, 2018 · 1 comment
Closed

Add note about calling parent::setUp() #2

jdietrch opened this issue Jan 26, 2018 · 1 comment

Comments

@jdietrch
Copy link

Note: This is a copy of sebastianbergmann/phpunit-documentation#236

After adding a setUp() method to my database testing class, the database initialization process wasn't happening properly anymore.This seems to be the same problem that was asked and answered here:
http://stackoverflow.com/questions/9490397/dbunit-in-phpunit-is-not-truncating-the-tables

So I added parent::setUp(); as the first line of my setUp() method, and it's working again.
It would be helpful if the phpunit documentation would make it clear that it is important to call parent::setUp() when overriding the setUp() method, in at least some conditions.

It should probably be mentioned in chapter 4 "Fixtures" where it talks about the setUp() method. Perhaps something like: "If you do override setUp(), don't forget to begin with a call to parent::setUp() if this or that condition applies. Otherwise, this or that thing won't happen anymore, with these undesireable results."

And it should probably also be mentioned somewhere in chapter 8 "Database Testing". Perhaps something like: "If you override setUp() as described in chapter 4, be sure to call parent::setUp(), for this and that reason. Otherwise, this or that other thing won't happen, with these undesireable results.

Of course, if one should always start setUp() with a call to parent::setUp(), a short note to that effect in the appropriate place(s) could save those who don't know or remember to do this some time and frustration.

@sebastianbergmann
Copy link
Owner

Closing as the chapter in question has been removed from the documentation (and DbUnit is no longer supported).

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

No branches or pull requests

2 participants