Completed
Push — master ( 215fc3...54bd62 )
by Mahmoud
03:11
created

ChargeUsersTest::testChargeWithPaypal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
namespace App\Containers\Payment\Tests\Unit;
4
5
use App\Containers\Payment\Factories\PaymentsFactory;
6
use App\Containers\Paypal\Tasks\CreatePaypalAccountObjectTask;
7
use App\Containers\Paypal\Tasks\ChargeWithPaypalTask;
8
use App\Containers\Stripe\Tasks\CreateStripeAccountObjectTask;
9
use App\Containers\Stripe\Tasks\ChargeWithStripeTask;
10
use App\Port\Tests\PHPUnit\Abstracts\TestCase;
11
use Illuminate\Support\Facades\App;
12
13
/**
14
 * Class ChargeUsersTest.
15
 *
16
 * @author Mahmoud Zalt <[email protected]>
17
 */
18
class ChargeUsersTest extends TestCase
19
{
20
21
    public function testChargeWithStripe()
22
    {
23
        // get the logged in user (create one if no one is logged in)
24
        $user = $this->registerAndLoginTestingUser();
25
26
        // create stripe account for this user
27
        $createStripeAccountAction = App::make(CreateStripeAccountObjectTask::class);
28
        $stripeAccount = $createStripeAccountAction->run($user, 'cus_8mBD5S1SoyD4zL', 'card_18Uck6KFvMcBUkvQorbBkYhR', 'credit', '4242', 'WsNM4K8puHbdS2VP');
0 ignored issues
show
Unused Code introduced by
$stripeAccount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
29
30
        $payId = 'ch_z8WDARKFvzcBUkvQzrbBvfhz';
31
32
        // mock the ChargeWithStripeTask external API call
33
        $this->mock(ChargeWithStripeTask::class)->shouldReceive('charge')->andReturn([
34
            'payment_method' => 'stripe',
35
            'description'    => $payId
36
        ]);
37
38
        $paymentsFactory = new PaymentsFactory();
39
        $result = $paymentsFactory->charge($user, 1000, 'USD');
40
41
        $this->assertEquals($result['payment_method'], 'stripe');
42
        $this->assertEquals($result['description'], $payId);
43
    }
44
45
    public function testChargeWithPaypal()
46
    {
47
        // get the logged in user (create one if no one is logged in)
48
        $user = $this->registerAndLoginTestingUser();
49
50
        // create stripe account for this user
51
        $createPaypalAccountAction = App::make(CreatePaypalAccountObjectTask::class);
52
        $paypalAccount = $createPaypalAccountAction->run($user, '8mBD5S1SoyD4zL');
0 ignored issues
show
Unused Code introduced by
$paypalAccount is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
53
54
        $payId = 'PAY-04797768K5905283VK6DGEMZ';
55
56
        // mock the ChargeWithPaypalTask external API call
57
        $this->mock(ChargeWithPaypalTask::class)->shouldReceive('charge')->andReturn([
58
            'payment_method' => 'paypal',
59
            'description'    => $payId
60
        ]);
61
62
        $paymentsFactory = new PaymentsFactory();
63
        $result = $paymentsFactory->charge($user, 1000, 'USD');
64
65
        $this->assertEquals($result['payment_method'], 'paypal');
66
        $this->assertEquals($result['description'], $payId);
67
    }
68
69
}
70