Skip to content

Commit

Permalink
Tests: Update _wp_timezone_choice_usort_callback() tests for consis…
Browse files Browse the repository at this point in the history
…tency.

* Use the same `@group` annotation as the other tests.
* Use `assertSame()` to verify the type of the result.
* Use `data_` prefix for the data provider.
* Use named data set in the data provider. This makes the output when using the `--testdox` option more descriptive and is helpful when trying to debug which data set from a data provider failed the test.
* Other minor corrections.

Reference: [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#repetitive-tests Core Handbook: Writing PHP Tests: Repetitive Tests].

Follow-up to [57145].

See #59953, #59647.

git-svn-id: https://develop.svn.wordpress.org/trunk@57146 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Nov 30, 2023
1 parent 4cee935 commit 36a7c6c
Showing 1 changed file with 18 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

/**
* Tests for the _wp_timezone_choice_usort_callback function.
* Tests for the _wp_timezone_choice_usort_callback() function.
*
* @group Functions.php
* @group function
*
* @covers ::_wp_timezone_choice_usort_callback
*/
Expand All @@ -12,19 +12,17 @@ class Tests_Functions_WpTimezoneChoiceUsortCallback extends WP_UnitTestCase {
/**
* @ticket 59953
*
* @dataProvider wp_timezone_choice_usort_callback_data
* @dataProvider data_wp_timezone_choice_usort_callback
*/
public function test__wp_timezone_choice_usort_callback( $unsorted, $sorted, $info ) {

public function test_wp_timezone_choice_usort_callback( $unsorted, $sorted ) {
usort( $unsorted, '_wp_timezone_choice_usort_callback' );

$this->assertEquals( $sorted, $unsorted, $info );
$this->assertSame( $sorted, $unsorted );
}


public function wp_timezone_choice_usort_callback_data() {
public function data_wp_timezone_choice_usort_callback() {
return array(
array(
'just GMT+' => array(
'unsorted' => array(
array(
'continent' => 'Etc',
Expand Down Expand Up @@ -99,10 +97,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: just GMT+',
),

array(
'mixed UTC and GMT' => array(
'unsorted' => array(
array(
'continent' => 'Etc',
Expand Down Expand Up @@ -177,10 +174,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: MIXED utc and GMT',
),

array(
'just alpha city' => array(
'unsorted' => array(
array(
'continent' => 'Etc',
Expand Down Expand Up @@ -255,10 +251,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: just alpha city',
),

array(
'not Etc continents are not sorted' => array(
'unsorted' => array(
array(
'continent' => 'd',
Expand Down Expand Up @@ -333,9 +328,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: not Etc continent are not sorted',
),
array(

'not Etc just t_continent' => array(
'unsorted' => array(
array(
'continent' => '',
Expand Down Expand Up @@ -410,9 +405,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: not Etc just t_city',
),
array(

'not Etc just t_city' => array(
'unsorted' => array(
array(
'continent' => '',
Expand Down Expand Up @@ -487,9 +482,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: not Etc just t_city',
),
array(

'not Etc just t_subcity' => array(
'unsorted' => array(
array(
'continent' => '',
Expand Down Expand Up @@ -564,9 +559,9 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => 'e',
),
),
'info' => '_wp_timezone_choice_usort_callback: just sub city',
),
array(

'just continent with Etc which pulls 1 to bottom' => array(
'unsorted' => array(
array(
'continent' => '',
Expand Down Expand Up @@ -641,7 +636,6 @@ public function wp_timezone_choice_usort_callback_data() {
't_subcity' => '',
),
),
'info' => '_wp_timezone_choice_usort_callback: just continent with etc which pulls 1 to bottom',
),
);
}
Expand Down

0 comments on commit 36a7c6c

Please sign in to comment.