diff --git a/tests/phpunit/includes/testcase.php b/tests/phpunit/includes/testcase.php index 2a2abf381e..933e66f76a 100644 --- a/tests/phpunit/includes/testcase.php +++ b/tests/phpunit/includes/testcase.php @@ -262,8 +262,15 @@ class WP_UnitTestCase extends PHPUnit_Framework_TestCase { } function assertEqualSets( $expected, $actual ) { - $this->assertEquals( array(), array_diff( $expected, $actual ) ); - $this->assertEquals( array(), array_diff( $actual, $expected ) ); + sort( $expected ); + sort( $actual ); + $this->assertEquals( $expected, $actual ); + } + + function assertEqualSetsWithIndex( $expected, $actual ) { + ksort( $expected ); + ksort( $actual ); + $this->assertEquals( $expected, $actual ); } function go_to( $url ) { diff --git a/tests/phpunit/tests/includes/helpers.php b/tests/phpunit/tests/includes/helpers.php new file mode 100755 index 0000000000..c589022e8c --- /dev/null +++ b/tests/phpunit/tests/includes/helpers.php @@ -0,0 +1,162 @@ +assertEqualSets( $expected, $actual ); + } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) { + return; + } + + $this->fail(); + } else { + $this->assertEqualSets( $expected, $actual ); + } + } + + /** + * @ticket 30522 + */ + function data_assertEqualSetsWithIndex() { + return array( + array( + array( 1, 2, 3 ), // test expected + array( 1, 2, 3 ), // test actual + false // exception expected + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + false + ), + array( + array( 1, 2, 3 ), + array( 2, 3, 1 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'b' => 2, 'c' => 3, 'a' => 1 ), + false + ), + array( + array( 1, 2, 3 ), + array( 1, 2, 3, 4 ), + true + ), + array( + array( 1, 2, 3, 4 ), + array( 1, 2, 3 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4 ), + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + true + ), + array( + array( 1, 2, 3 ), + array( 3, 4, 2, 1 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'c' => 3, 'b' => 2, 'd' => 4, 'a' => 1 ), + true + ), + array( + array( 1, 2, 3 ), + array( 1, 2, 3, 3 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'a' => 1, 'b' => 2, 'c' => 3, 'd' => 3 ), + true + ), + array( + array( 1, 2, 3 ), + array( 2, 3, 1, 3 ), + true + ), + array( + array( 'a' => 1, 'b' => 2, 'c' => 3 ), + array( 'c' => 3, 'b' => 2, 'd' => 3, 'a' => 1 ), + true + ), + ); + } + /** + * @dataProvider data_assertEqualSetsWithIndex + * @ticket 30522 + */ + function test_assertEqualSetsWithIndex( $expected, $actual, $exception ) { + if ( $exception ) { + try { + $this->assertEqualSetsWithIndex( $expected, $actual ); + } catch ( PHPUnit_Framework_ExpectationFailedException $ex ) { + return; + } + + $this->fail(); + } else { + $this->assertEqualSetsWithIndex( $expected, $actual ); + } + } +}