Skip to content

Commit

Permalink
Tests: Stop using deprecated setMethods method (#427)
Browse files Browse the repository at this point in the history
* Tests: Stop using deprecated setMethods method

Use `onlyMethods()` instead, which ensures that the method that is being mocked does exist in the class being mocked.

* Tests: use onlyMethods() only if it exists
  • Loading branch information
GaryJones committed Oct 5, 2021
1 parent 3e5e9b2 commit bb6d44b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/Unit/Integrations/IntegrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public function test_an_integration_can_be_registered_to_a_new_Integrations_obje
* @uses \Parsely\Integrations\Integrations::register
*/
public function test_registered_integrations_have_their_integrate_method_called(): void {
$mock_integration = $this->getMockBuilder( Integration::class )->setMethods( array( 'integrate' ) )->getMock();
$mock_builder = $this->getMockBuilder( Integration::class );
// See https://github.com/Parsely/wp-parsely/issues/426.
if ( method_exists( $mock_builder, 'onlyMethods' ) ) {
$mock_integration = $mock_builder->onlyMethods( array( 'integrate' ) )->getMock();
} else {
$mock_integration = $mock_builder->setMethods( array( 'integrate' ) )->getMock();
}
$mock_integration->expects( $this->once() )->method( 'integrate' );

$integrations = new Integrations();
Expand Down

0 comments on commit bb6d44b

Please sign in to comment.