Completed
Push — master ( c4f586...d3edc0 )
by Mahmoud
03:09
created

ChargeUsersTest::testChargeWithStripe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
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\Port\Tests\PHPUnit\Abstracts\TestCase;
8
use Illuminate\Support\Facades\App;
9
10
/**
11
 * Class ChargeUsersTest.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class ChargeUsersTest extends TestCase
16
{
17
18
    public function testChargeWithStripe()
19
    {
20
        // get the logged in user (create one if no one is logged in)
21
        $user = $this->registerAndLoginTestingUser();
22
23
        // create stripe account for this user
24
        $createStripeAccountAction = App::make(CreateStripeAccountObjectTask::class);
25
        $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...
26
27
        $payId = 'ch_z8WDARKFvzcBUkvQzrbBvfhz';
28
29
        // mock the ChargeWithStripeTask external API call
30
        $this->mock(ChargeWithStripeTask::class)->shouldReceive('charge')->andReturn([
31
            'payment_method' => 'stripe',
32
            'description'    => $payId
33
        ]);
34
35
        $stripe = App::make(ChargeWithStripeTask::class);
36
        $result = $stripe->charge($user, 1000, 'USD');
37
38
        $this->assertEquals($result['payment_method'], 'stripe');
39
        $this->assertEquals($result['description'], $payId);
40
    }
41
42
}
43