Last active
June 24, 2020 18:15
-
-
Save karakanb/f1fdf77827aefd55f90cdc791f1872c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
namespace Tests\Feature; | |
use App\User; | |
use Laravel\Cashier\SubscriptionBuilder; | |
use Tests\TestCase; | |
use function route; | |
class PlansTest extends TestCase | |
{ | |
public function testSubscriptionIsSuccessfullyCreatedWithCoupon() | |
{ | |
// Disable the authentication middleware, we don't need it. | |
$this->withoutMiddleware([Authenticate::class]); | |
// Prepare request variables. | |
$paymentMethodId = 'payment-method'; | |
$couponCode = 'SOME_COUPON'; | |
// Prepare the subscription builder mock. | |
$subscriptionBuilder = $this->prophesize(SubscriptionBuilder::class); | |
$subscriptionBuilder->withCoupon($couponCode) | |
->shouldBeCalled(); | |
$subscriptionBuilder->create($paymentMethodId) | |
->shouldBeCalled(); | |
// Prepare the user mock | |
$user = $this->prophesize(User::class); | |
$user->newSubscription('default', 'standard') | |
->shouldBeCalled() | |
->willReturn($subscriptionBuilder->reveal()); | |
// Perform the request as our user mock. | |
$testRoute = route('plans.save', ['plan' => 'standard']); | |
$response = $this->actingAs($user->reveal()) | |
->post($testRoute, [ | |
'paymentMethodId' => $paymentMethodId, | |
'couponCode' => $couponCode, | |
]); | |
// Assert that everything went smoothly. | |
$response->assertRedirect(route('home')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment