mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Add unit test
This commit is contained in:
parent
eb86f8a71d
commit
4a95f22e75
3 changed files with 39 additions and 19 deletions
|
@ -16,7 +16,7 @@ use WooCommerce\PayPalCommerce\WcSubscriptions\Helper\SubscriptionHelper;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'wc-subscriptions.helper' => static function ( ContainerInterface $container ): SubscriptionHelper {
|
'wc-subscriptions.helper' => static function ( ContainerInterface $container ): SubscriptionHelper {
|
||||||
return new SubscriptionHelper( $container->get( 'wcgateway.settings' ) );
|
return new SubscriptionHelper();
|
||||||
},
|
},
|
||||||
'wc-subscriptions.renewal-handler' => static function ( ContainerInterface $container ): RenewalHandler {
|
'wc-subscriptions.renewal-handler' => static function ( ContainerInterface $container ): RenewalHandler {
|
||||||
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
$logger = $container->get( 'woocommerce.logger.woocommerce' );
|
||||||
|
|
|
@ -16,7 +16,6 @@ use WC_Product_Subscription_Variation;
|
||||||
use WC_Subscription;
|
use WC_Subscription;
|
||||||
use WC_Subscriptions;
|
use WC_Subscriptions;
|
||||||
use WC_Subscriptions_Product;
|
use WC_Subscriptions_Product;
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|
||||||
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,22 +23,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
|
||||||
*/
|
*/
|
||||||
class SubscriptionHelper {
|
class SubscriptionHelper {
|
||||||
|
|
||||||
/**
|
|
||||||
* The settings.
|
|
||||||
*
|
|
||||||
* @var Settings
|
|
||||||
*/
|
|
||||||
private $settings;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SubscriptionHelper constructor.
|
|
||||||
*
|
|
||||||
* @param Settings $settings The settings.
|
|
||||||
*/
|
|
||||||
public function __construct( Settings $settings ) {
|
|
||||||
$this->settings = $settings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the current product is a subscription.
|
* Whether the current product is a subscription.
|
||||||
*
|
*
|
||||||
|
@ -308,7 +291,7 @@ class SubscriptionHelper {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function previous_transaction( WC_Subscription $subscription ): string {
|
public function previous_transaction( WC_Subscription $subscription ): string {
|
||||||
$orders = $subscription->get_related_orders( 'all', array( 'parent', 'renewal' ) );
|
$orders = $subscription->get_related_orders( 'ids', array( 'parent', 'renewal' ) );
|
||||||
if ( ! $orders ) {
|
if ( ! $orders ) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace WooCommerce\PayPalCommerce\WcSubscriptions\Helper;
|
||||||
|
|
||||||
|
use Mockery;
|
||||||
|
use WC_Order;
|
||||||
|
use WC_Subscription;
|
||||||
|
use WooCommerce\PayPalCommerce\TestCase;
|
||||||
|
use function Brain\Monkey\Functions\when;
|
||||||
|
|
||||||
|
class SubscriptionHelperTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testPreviousTransaction()
|
||||||
|
{
|
||||||
|
$subscription = Mockery::mock(WC_Subscription::class);
|
||||||
|
$subscription->shouldReceive('get_related_orders')
|
||||||
|
->andReturn(
|
||||||
|
[
|
||||||
|
1 => 1,
|
||||||
|
3 => 3,
|
||||||
|
2 => 2,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$wc_order = Mockery::mock(WC_Order::class);
|
||||||
|
$wc_order->shouldReceive('get_status')->andReturn('processing');
|
||||||
|
$wc_order->shouldReceive('get_transaction_id')->andReturn('ABC123');
|
||||||
|
|
||||||
|
when('wc_get_order')->justReturn($wc_order);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'ABC123',
|
||||||
|
(new SubscriptionHelper())->previous_transaction($subscription)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue