Skip to content

Commit

Permalink
Tools/BrainMonkeyRaceCondition: add tests with PHP 8.0+ named parameters
Browse files Browse the repository at this point in the history
The commit in PR 322 in which the function call retrieving the parameter was changed from the WPCS method to the PHPCSUtils method already added support for this.

This commit just adds some tests to safeguard it.
  • Loading branch information
jrfnl committed Nov 4, 2023
1 parent 6ea3d9b commit 85c9bd1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
37 changes: 37 additions & 0 deletions Yoast/Tests/Tools/BrainMonkeyRaceConditionUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,41 @@ class BrainMonkeyBasedTest extends TestCase {

// Do something to satisfy expectations.
}

/*
* Tests involving PHP 8.0+ named parameters.
*/
public function test_NOT_race_condition_wrong_param_name() {
Functions\expect( not_functionname: "apply_filters")->times(5);

Filters\ExpectDone ( 'filter_name' );

// Do something to satisfy expectations.
}

public function test_NOT_race_condition_named_param_not_for_hook() {
Functions\expect( function_name: "other_function")->times(5);

Filters\ExpectDone ( 'filter_name' );

// Do something to satisfy expectations.
}

public function test_filter_race_condition_named_param() {
Functions\expect( function_name: "apply_filters")->twice();

Filters\ExpectApplied ( 'filter_name' )
->with( true );

// Do something to satisfy expectations.
}

public function test_action_race_condition_named_param_unconventional_order() {
\Brain\Monkey\Functions\Expect( something: foo, function_name: 'do_action' )->once();

Actions\expectDone( 'yoast\action_name' )
->with( $param );

// Do something to satisfy expectations.
}
}
2 changes: 2 additions & 0 deletions Yoast/Tests/Tools/BrainMonkeyRaceConditionUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function getErrorList(): array {
113 => 1,
122 => 1,
131 => 1,
176 => 1,
185 => 1,
];
}

Expand Down

0 comments on commit 85c9bd1

Please sign in to comment.