wordpress-develop/tests/phpunit/tests/hooks/iterator.php
Sergey Biryukov 8be943d06e Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate.
This ensures that not only the array values being compared are equal, but also that their type is the same.

These new methods replace most of the existing instances of `assertEqualSets()` and `assertEqualSetsWithIndex()`.

Going forward, stricter type checking by using `assertSameSets()` or `assertSameSetsWithIndex()` should generally be preferred, to make the tests more reliable.

Follow-up to [48937].

See #38266.

git-svn-id: https://develop.svn.wordpress.org/trunk@48939 602fd350-edb4-49c9-b593-d223f7449a82
2020-09-04 07:01:00 +00:00

33 lines
909 B
PHP

<?php
/**
* Test the Iterator implementation of WP_Hook
*
* @group hooks
*/
class Tests_WP_Hook_Iterator extends WP_UnitTestCase {
public function test_foreach() {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = rand( 1, 100 );
$accepted_args = rand( 1, 100 );
$hook->add_filter( $tag, $callback_one, $priority, $accepted_args );
$hook->add_filter( $tag, $callback_two, $priority + 1, $accepted_args );
$functions = array();
$priorities = array();
foreach ( $hook as $key => $callbacks ) {
$priorities[] = $key;
foreach ( $callbacks as $function_index => $the_ ) {
$functions[] = $the_['function'];
}
}
$this->assertSameSets( array( $priority, $priority + 1 ), $priorities );
$this->assertSameSets( array( $callback_one, $callback_two ), $functions );
}
}