Skip to content

Commit

Permalink
PHP 8.1 | Tests: fix two incomplete mocks
Browse files Browse the repository at this point in the history
Both the `Addon_Activate_Action_Test::test_activate_addon_activation_result_is_null()`, as well as the `Addon_Install_Action_Test::test_install_addon_thows_when_install_fails()` test would throw a "Exception::__construct(): Passing null to parameter #1 ($message) of type string is deprecated" deprecation notice on PHP 8.1 due to the mock for WP_Error not being complete (not returning a value for `WP_Error::get_error_message()`).

Fixed now.

Includes renaming two tests in the `Addon_Activate_Action_Test` class to be more descriptive.
  • Loading branch information
jrfnl committed Nov 30, 2021
1 parent a62fd43 commit aa52607
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function test_activate_addon_user_has_no_activate_permissions() {
/**
* Tests if an activated addon can be activated "again".
*/
public function test_activate_addon_is_already_installed() {
public function test_activate_addon_is_already_activated() {

Monkey\Functions\expect( 'current_user_can' )
->once()
Expand All @@ -89,7 +89,7 @@ public function test_activate_addon_is_already_installed() {
/**
* Tests if an exception is thrown on activation error.
*/
public function test_activate_addon_activation_result_is_null() {
public function test_activate_addon_activation_when_activation_fails() {

Monkey\Functions\expect( 'current_user_can' )
->once()
Expand Down Expand Up @@ -117,7 +117,8 @@ public function test_activate_addon_activation_result_is_null() {

$wp_error
->expects( 'get_error_message' )
->once();
->once()
->andReturn( '' );

Monkey\Functions\expect( 'activate_plugin' )
->once()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ public function test_install_addon_thows_when_install_fails() {

$wp_error
->expects( 'get_error_message' )
->once();
->once()
->andReturn( '' );

$plugin_upgrader = Mockery::mock( 'overload:' . Plugin_Upgrader::class );

Expand Down

0 comments on commit aa52607

Please sign in to comment.