[wp-trac] [WordPress Trac] #35199: WP_UnitTest_Generator_Sequence is generating incorrect sequences
WordPress Trac
noreply at wordpress.org
Sun Mar 6 04:07:51 UTC 2016
#35199: WP_UnitTest_Generator_Sequence is generating incorrect sequences
------------------------------+----------------------
Reporter: OddOneOut | Owner:
Type: defect (bug) | Status: closed
Priority: normal | Milestone:
Component: Build/Test Tools | Version: 4.4
Severity: normal | Resolution: invalid
Keywords: | Focuses:
------------------------------+----------------------
Comment (by boonebgorges):
Replying to [comment:9 OddOneOut]:
> What about the current invalid behaviour i.e. "Post title 0, Post
content 1, Post excerpt 2" (which should be "Post title 1, Post content 1,
Post excerpt 1")?
The behavior is only "invalid" if you write tests that expect the
incrementor in these fields to be the same for the same post. The
suggestion in this thread is that you do not write tests with this
expectation, but instead either (a) use the dynamically generated values
for your assertions, or (b) feed specific values into the factory method
when building the features.
That said, if you can provide a patch or suggest a strategy that will
enforce this behavior - using the same incrementor for a given feature -
without rolling back the general improvement of persistent incrementors
throughout the test run, I don't think there's any harm in including it.
>
> Also, the issue I'm mentioning here is not whether we should use
`$post1->post_title` or just "Post title 1" to test, but about not relying
on the global state to test. At least there should be a way to reset the
factory or disable the static incrementor (as I've said above).
>
If "not relying on the global state to test" means "start incrementors
over with each test", then that would mean reintroducing the behavior that
[35244] was meant to circumvent. Maybe it wasn't fully explained in that
commit message or ticket, but non-persistent incrementors cause
significant problems in the context of WP's janky automated test suite.
For example, generating a user fixture will create a user with an email
address that uses the incrementor. If the test fails to clean up after
itself properly, a future test will fail due to users not being inserted
correctly. This has caused hours of painful debugging for me personally in
the past.
I think that if you need a reset method, it indicates that your tests are
doing something unnecessarily fragile. That being said, if you'd like to
provide a patch for such a method, feel free to post it here and reopen
the ticket. Thanks!
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35199#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list