-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a7a05e
commit b0fc45f
Showing
7 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Adding Compatibility Service to assist with flagging possible compatibility issues in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Compatibility_Service class | ||
* | ||
* @package WooCommerce\Payments | ||
*/ | ||
|
||
namespace WCPay; | ||
|
||
use WC_Payments_API_Client; | ||
use WCPay\Exceptions\API_Exception; | ||
|
||
defined( 'ABSPATH' ) || exit; // block direct access. | ||
|
||
/** | ||
* Class to send compatibility data to the server. | ||
*/ | ||
class Compatibility_Service { | ||
/** | ||
* Client for making requests to the WooCommerce Payments API | ||
* | ||
* @var WC_Payments_API_Client | ||
*/ | ||
private $payments_api_client; | ||
|
||
/** | ||
* Constructor for Compatibility_Service. | ||
* | ||
* @param WC_Payments_API_Client $payments_api_client WooCommerce Payments API client. | ||
*/ | ||
public function __construct( WC_Payments_API_Client $payments_api_client ) { | ||
$this->payments_api_client = $payments_api_client; | ||
} | ||
|
||
/** | ||
* Initializes this class's WP hooks. | ||
* | ||
* @return void | ||
*/ | ||
public function init_hooks() { | ||
add_action( 'woocommerce_payments_account_refreshed', [ $this, 'update_compatibility_data' ] ); | ||
} | ||
|
||
/** | ||
* Gets the data we need to confirm compatibility and sends it to the server. | ||
* | ||
* @return void | ||
*/ | ||
public function update_compatibility_data() { | ||
try { | ||
$this->payments_api_client->update_compatibility_data( | ||
[ | ||
'woopayments_version' => WCPAY_VERSION_NUMBER, | ||
'woocommerce_version' => WC_VERSION, | ||
] | ||
); | ||
} catch ( API_Exception $e ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch | ||
// The exception is already logged if logging is on, nothing else needed. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* Class Compatibility_Service_Test | ||
* | ||
* @package WooCommerce\Payments\Tests | ||
*/ | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use WCPay\Compatibility_Service; | ||
|
||
/** | ||
* Unit tests related to the Compatibility_Service class. | ||
*/ | ||
class Compatibility_Service_Test extends WCPAY_UnitTestCase { | ||
/** | ||
* Mock WC_Payments_API_Client. | ||
* | ||
* @var WC_Payments_API_Client|MockObject | ||
*/ | ||
private $mock_api_client; | ||
|
||
/** | ||
* Compatibility_Service. | ||
* | ||
* @var Compatibility_Service | ||
*/ | ||
private $compatibility_service; | ||
|
||
/** | ||
* Pre-test setup | ||
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
|
||
$this->mock_api_client = $this->createMock( WC_Payments_API_Client::class ); | ||
$this->compatibility_service = new Compatibility_Service( $this->mock_api_client ); | ||
$this->compatibility_service->init_hooks(); | ||
} | ||
|
||
public function test_registers_woocommerce_filters_properly() { | ||
$priority = has_filter( 'woocommerce_payments_account_refreshed', [ $this->compatibility_service, 'update_compatibility_data' ] ); | ||
$this->assertEquals( 10, $priority ); | ||
} | ||
|
||
public function test_update_compatibility_data() { | ||
// Arrange: Create the expected value to be passed to update_compatibility_data. | ||
$expected = [ | ||
'woopayments_version' => WCPAY_VERSION_NUMBER, | ||
'woocommerce_version' => WC_VERSION, | ||
]; | ||
|
||
// Arrange/Assert: Set the expectations for update_compatibility_data. | ||
$this->mock_api_client | ||
->expects( $this->once() ) | ||
->method( 'update_compatibility_data' ) | ||
->with( $expected ); | ||
|
||
// Act: Call the method we're testing. | ||
$this->compatibility_service->update_compatibility_data(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters