-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
(REF) CiviUnitTestCase - Cleanup and simplify the DB-reset mechanism #25178
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(Standard links)
|
civibot, test this please |
1 similar comment
civibot, test this please |
The property is initialized to FALSE. It seems that the idea was to let some classes override this, but it is never used.
This function returns a connection that nobody uses. It has only one caller. It's mostly interesting because it can reset the database. Hiding it under the name `getConnection` is misleading.
In practice, this check is the first thing done by `setUpBeforeClass()`. Might as well move it there. Technically, this check is also called by way of `setUp()`, but it's redundant at that point. (Constants are constants...)
totten
force-pushed
the
master-civiunitestcase
branch
from
December 16, 2022 05:14
371682c
to
168ff84
Compare
…or method-overrides.
At this point, it's just a bunch of verbosely written conditions that appear to be trueisms; * When called via `setUpBeforeClass()`, the `$perClass` flag is TRUE, so it does the reset. * When called via `setUp()`, the `$object` flag is non-null, so it does the reset. At this point, the actual reset bit is 1-line. Easier to just call that.
totten
changed the title
(EXP) (Do not merge) CiviUnitTestCase - Multiple cleanups
CiviUnitTestCase - Cleanup and simplify the DB-reset mechanism
Dec 16, 2022
totten
changed the title
CiviUnitTestCase - Cleanup and simplify the DB-reset mechanism
(REF) CiviUnitTestCase - Cleanup and simplify the DB-reset mechanism
Dec 16, 2022
I've filled in the description and removed the "do not merge" flag. Tests are passing. If you want to skim the patch, I suggest reading the "Before/After" summary - and then the individual commits. (The aggregated diff is a bit crisscrossy, but the individual ones are very bite-sized.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Simplify the code which handles data-setup in
CiviUnitTestCase
. This removes several properties and functions which are not really used. Instead, callCiviEnvBuilder
(which includes similar/better helpers -- and which is shared byCivi\Test::headless()
,Civi\Test::e2e()
,Api4TestBase
, and most civix testing templates).Before
Primarily, the functionality here is that
setUpBeforeClass()
andsetUp()
call_populateDB()
,There is a series of inter-related properties and functions which reference each other - but they are not used externally. These are:
After
Primarily, the functionality here is that
setUpBeforeClass()
andsetUp()
callbuildEnvironment()->apply(TRUE)
,All the "Before" methods are removed. Instead, there is one new, short method:
Comments
The existing policy in
CiviUnitTestCase
have a very strong tendency to do DB resets. The PR preserves this policy.Most of the commits are fairly basic: search for "XX", find "XX" is only used 0-1 times, and remove "XX".
The most interesting commit is probably 8cfba74 -- that's where it becomes apparent that the funny conditionals in
_populateDB()
don't serve a purpose, and that$DBResetRequired
is inert (even though ~30 test-classes mention it).This file has a huge amount of implicit test-coverage by way of
./tests/phpunit/
--CiviUnitTestCase
is extended by 450+ test-classes.