-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
feat: make migration/seed settings flexible on database testing #3993
feat: make migration/seed settings flexible on database testing #3993
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have to look at this one on mobile, but I like breaking these out. First and foremost we must be absolutely sure that current tests will still work after this change (I.e. still respects $refresh
). Second IMO we should go ahead and deprecate $refresh
and rely on these going forward.
These changes will also require updates to the User Guide.
68eab49
to
b727973
Compare
Updated the User Guide. |
Only |
@kenjis it's been happening from time to time. Not related to your PR, we need to look into why the test table is persisting. |
I see. Thanks! |
|
You just need to re-run actions until it goes green. |
@paulbalandan How do I re-run? |
eac4761
to
bd1d69a
Compare
I rebased. Can #4015 help? |
Oh no! |
See #4015 (comment). |
bd1d69a
to
16d880e
Compare
All tests passed. |
@MGatner Is something wrong with this PR? |
Not necessarily! It's more complicated than I am able to review on mobile, which is where I do most of my reviews. I will set aside some desktop time later to do it. |
@MGatner Okay, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks good. My main concern is around the "once" aspect. As is, with the private
scope on the flags, migrations & seeds will only run once for the entire run of PHPUnit, and yet will be dependent on the class-specific settings of whichever test case is run first. Consider these three test cases all in the same project:
class FooTest extends CIDatabaseTestCase
{
protected $migrateOnce = true;
protected $namespace = 'Tests\Support';
}
class BarTest extends CIDatabaseTestCase
{
protected $migrateOnce = false;
protected $namespace = null;
}
class BamTest extends CIDatabaseTestCase
{
protected $migrateOnce = true;
protected $namespace = 'App';
}
Depending on which are run and in which order (and by which thread) they could all leave the database in very different states.
In my opinion, the "once" methods should apply per test case (file), rather than for the whole suite - and if we want to offer the option for a single static database test configuration then it should be handled in a bootstrap, not the test cases themselves.
I hope that makes sense.
@MGatner Thank you for the review. See https://github.com/codeigniter4/CodeIgniter4/pull/3993/files#diff-7591a921e2ba957a20a6e334d50bb134de0a53a4c4c4a3f01e27d001b9bae4c6R449-R458 I added test for
|
Oh! Sorry then, that was my mistake. I wonder what kind of weird scopiness is happening that Given this, I approve the PR, but I will wait for merge. |
I am ok with this 👍 |
@samsonasik do you understand how the scoping is working out such that the "once" variables are toggled for every file? |
@MGatner that rely on |
Yes. Since |
This method is called after the test suite class is tested: /**
* Reset $doneMigration and $doneSeed
*
* @afterClass
*/
public static function resetMigrationSeedCount()
{
self::$doneMigration = false;
self::$doneSeed = false;
} Notice the |
I totally missed that. Thanks for explaining 🤩 |
Description
Now you can't disable migration on database testing if you want.
And running migration/seed on each test may slow tests.
$migrate = false
$migrateOnce = true
$seedOnce = true
Checklist: