mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-20 19:24:32 +00:00
Tests: Resolve WP_Query test failures on MariaDB due to indeterminate sort order.
[54768] added a few tests to verify that caching within `WP_Query` is bypassed when the `SELECT` clause has been modified via a filter, to avoid cache key collisions and the returning of incomplete or unexpected results.
However, creating several posts with the same date/time fields can result in inconsistent sort ordering between MySQL and MariaDB, as each engine refines the order further using a different index.
This commit aims to stabilize the tests by using `assertEqualSets()` instead of `assertEquals()`, since testing the order is out of their scope. Includes removing `array_unshift()` and `array_reverse()` calls as no longer needed.
This resolves a few test failures on MariaDB along the lines of:
{{{
Tests_Query_FieldsClause::test_should_limit_fields_to_id_and_parent_subset
Posts property for first query is not of expected form.
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
0 => stdClass Object (
- 'ID' => 36019
+ 'ID' => 36015
'post_parent' => 0
)
1 => stdClass Object (
- 'ID' => 36018
+ 'ID' => 36016
'post_parent' => 0
)
2 => stdClass Object (...)
3 => stdClass Object (
- 'ID' => 36016
+ 'ID' => 36018
'post_parent' => 0
)
4 => stdClass Object (
- 'ID' => 36015
+ 'ID' => 36019
'post_parent' => 0
)
)
/tmp/wp-test-runner/tests/phpunit/tests/query/fieldsClause.php:67
/tmp/wp-test-runner/phpunit-5.7.phar:598
}}}
Follow-up to [54768].
Props peterwilsoncc, SergeyBiryukov.
See #57012.
git-svn-id: https://develop.svn.wordpress.org/trunk@54829 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -54,23 +54,19 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$expected = array();
|
||||
foreach ( self::$post_ids as $post_id ) {
|
||||
// Use array_shift to populate in the reverse order.
|
||||
array_unshift(
|
||||
$expected,
|
||||
(object) array(
|
||||
'ID' => $post_id,
|
||||
'post_parent' => 0,
|
||||
)
|
||||
$expected[] = (object) array(
|
||||
'ID' => $post_id,
|
||||
'post_parent' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,15 +82,15 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$q = new WP_Query( $query_args );
|
||||
|
||||
$expected = array_reverse( self::$post_ids );
|
||||
$expected = self::$post_ids;
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,15 +106,15 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$q = new WP_Query( $query_args );
|
||||
|
||||
$expected = array_map( 'get_post', array_reverse( self::$post_ids ) );
|
||||
$expected = array_map( 'get_post', self::$post_ids );
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,25 +135,21 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$expected = array();
|
||||
foreach ( self::$post_ids as $post_id ) {
|
||||
// Use array_shift to populate in the reverse order.
|
||||
array_unshift(
|
||||
$expected,
|
||||
(object) array(
|
||||
'ID' => $post_id,
|
||||
'post_parent' => 0,
|
||||
'test_post_fields' => 1,
|
||||
'test_post_clauses' => 2,
|
||||
)
|
||||
$expected[] = (object) array(
|
||||
'ID' => $post_id,
|
||||
'post_parent' => 0,
|
||||
'test_post_fields' => '1',
|
||||
'test_post_clauses' => '2',
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -176,16 +168,16 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$q = new WP_Query( $query_args );
|
||||
|
||||
// Fields => ID does not include the additional fields.
|
||||
$expected = array_reverse( self::$post_ids );
|
||||
// `fields => ids` does not include the additional fields.
|
||||
$expected = self::$post_ids;
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,19 +196,19 @@ class Tests_Query_FieldsClause extends WP_UnitTestCase {
|
||||
|
||||
$q = new WP_Query( $query_args );
|
||||
|
||||
$expected = array_map( 'get_post', array_reverse( self::$post_ids ) );
|
||||
$expected = array_map( 'get_post', self::$post_ids );
|
||||
foreach ( $expected as $post ) {
|
||||
$post->test_post_fields = 1;
|
||||
$post->test_post_clauses = 2;
|
||||
$post->test_post_fields = '1';
|
||||
$post->test_post_clauses = '2';
|
||||
}
|
||||
|
||||
$this->assertEquals( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertEqualSets( $expected, $q->posts, 'Posts property for first query is not of expected form.' );
|
||||
$this->assertSame( 5, $q->found_posts, 'Number of found posts is not five.' );
|
||||
$this->assertEquals( 1, $q->max_num_pages, 'Number of found pages is not one.' );
|
||||
|
||||
// Test the second query's results match.
|
||||
$q2 = new WP_Query( $query_args );
|
||||
$this->assertEquals( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
$this->assertEqualSets( $expected, $q2->posts, 'Posts property for second query is not in the expected form.' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user