[wp-trac] [WordPress Trac] #30522: WP_UnitTestCase::assertEqualSets can pass incorrectly

WordPress Trac noreply at wordpress.org
Thu Nov 27 23:17:11 UTC 2014


#30522: WP_UnitTestCase::assertEqualSets can pass incorrectly
------------------------------+------------------------------
 Reporter:  dd32              |       Owner:
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  Awaiting Review
Component:  Build/Test Tools  |     Version:  trunk
 Severity:  normal            |  Resolution:
 Keywords:  has-patch         |     Focuses:
------------------------------+------------------------------
Changes (by dd32):

 * version:   => trunk


Comment:

 > I believe there is a need to include a test that ensures the arrays are
 the same without involving sorting.
 > e.g. for a query where you want to get posts 1,4,3,2 in that order, then
 the expected array should be ( 1,4,3,2 ) in that order.
 > Question: Can't assertEquals be used for that specific test?

 Yes, AssertEquals should be used when both value and order of the returned
 data is important.
 It should not be used when the order is unimportant, or potentially
 undefined, which is where assertEqualSet was introduced.

 > I reported one of the problems with the PHPUnit tests tests could be
 that assertEqualSets ignores duplicate keys so doesn't notice get_pages()
 returning array(3,4,5,5) when it should be array(3,4,5);
 That's this exact bug :) I guess it got missed on Slack, or no-one created
 a Ticket for it.

 > I wrote the tests in r30096 for #12668. I believe assertEquals respects
 order and assertEqualSets does not
 That's a correct assumption.
 The tests look good to me, based on the idea that you expect the order of
 the comments to be returned in the specific order. However, those tests
 may actually fail on older MySQL, see #30478 as to why

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30522#comment:8>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list