1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\Stripe\Tests\Unit; |
4
|
|
|
|
5
|
|
|
use App\Containers\Stripe\Tasks\CreateStripeAccountObjectTask; |
6
|
|
|
use App\Containers\Stripe\Tasks\ChargeWithStripeTask; |
7
|
|
|
use App\Containers\Stripe\Tests\TestCase; |
8
|
|
|
use App\Ship\Features\Payment\Proxies\PaymentsProxy; |
9
|
|
|
use Illuminate\Support\Facades\App; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ChargeUsersTest. |
13
|
|
|
* |
14
|
|
|
* @author Mahmoud Zalt <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class ChargeUsersTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
public function testChargeWithStripe() |
20
|
|
|
{ |
21
|
|
|
// get the logged in user (create one if no one is logged in) |
22
|
|
|
$user = $this->createTestingUser(); |
23
|
|
|
|
24
|
|
|
// create stripe account for this user |
25
|
|
|
$createStripeAccountAction = App::make(CreateStripeAccountObjectTask::class); |
26
|
|
|
$stripeAccount = $createStripeAccountAction->run($user, 'cus_8mBD5S1SoyD4zL', 'card_18Uck6KFvMcBUkvQorbBkYhR', 'credit', '4242', 'WsNM4K8puHbdS2VP'); |
|
|
|
|
27
|
|
|
|
28
|
|
|
$payId = 'ch_z8WDARKFvzcBUkvQzrbBvfhz'; |
29
|
|
|
|
30
|
|
|
// mock the ChargeWithStripeTask external API call |
31
|
|
|
$this->mock(ChargeWithStripeTask::class)->shouldReceive('charge')->andReturn([ |
32
|
|
|
'payment_method' => 'stripe', |
33
|
|
|
'description' => $payId |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
$stripe = App::make(ChargeWithStripeTask::class); |
37
|
|
|
$result = $stripe->charge($user, 1000, 'USD'); |
38
|
|
|
|
39
|
|
|
$this->assertEquals($result['payment_method'], 'stripe'); |
40
|
|
|
$this->assertEquals($result['description'], $payId); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testChargeWithStripeThroughPaymentProxy() |
44
|
|
|
{ |
45
|
|
|
// get the logged in user (create one if no one is logged in) |
46
|
|
|
$user = $this->createTestingUser(); |
47
|
|
|
|
48
|
|
|
// create stripe account for this user |
49
|
|
|
$createStripeAccountAction = App::make(CreateStripeAccountObjectTask::class); |
50
|
|
|
$stripeAccount = $createStripeAccountAction->run($user, 'cus_8mBD5S1SoyD4zL', 'card_18Uck6KFvMcBUkvQorbBkYhR', 'credit', '4242', 'WsNM4K8puHbdS2VP'); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$payId = 'ch_z8WDARKFvzcBUkvQzrbBvfhz'; |
53
|
|
|
|
54
|
|
|
// mock the ChargeWithStripeTask external API call |
55
|
|
|
$this->mock(ChargeWithStripeTask::class)->shouldReceive('run')->andReturn([ |
56
|
|
|
'payment_method' => 'stripe', |
57
|
|
|
'description' => $payId |
58
|
|
|
]); |
59
|
|
|
|
60
|
|
|
// the proxy payment method |
61
|
|
|
$result = $user->charge(1000, 'USD'); |
62
|
|
|
|
63
|
|
|
$this->assertEquals($result['payment_method'], 'stripe'); |
64
|
|
|
$this->assertEquals($result['description'], $payId); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.