wordpress-develop/tests/phpunit/tests/hooks/iterator.php
John Blackbourn 029bea45b0 Build/Test Tools: Reduce the use of unnecessary randomness in tests.
This increases the overall reliability of the tests.

Props johnillo

Fixes #37371


git-svn-id: https://develop.svn.wordpress.org/trunk@52389 602fd350-edb4-49c9-b593-d223f7449a82
2021-12-19 13:42:37 +00:00

34 lines
912 B
PHP

<?php
/**
* Test the Iterator implementation of WP_Hook
*
* @group hooks
* @covers WP_Hook::add_filter
*/
class Tests_Hooks_Iterator extends WP_UnitTestCase {
public function test_foreach() {
$callback_one = '__return_null';
$callback_two = '__return_false';
$hook = new WP_Hook();
$tag = __FUNCTION__;
$priority = 1;
$accepted_args = 2;
$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 );
}
}