diff --git a/tests/feature/MigrateSubscriptionTest.php b/tests/feature/MigrateSubscriptionTest.php index 1d08e94..dcc4630 100644 --- a/tests/feature/MigrateSubscriptionTest.php +++ b/tests/feature/MigrateSubscriptionTest.php @@ -52,9 +52,7 @@ public function can_migrate_a_yearly_plan_in_test_phase_to_a_monthly_plan_immedi $subscription = $this->user->active_subscription; $this->assertEquals('monthly', $subscription->plan->type); $this->assertEqualsWithDelta(Carbon::now(), $subscription->starts_at, 1); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(NewSubscription::class); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(SubscriptionMigrated::class); } @@ -99,7 +97,6 @@ public function can_migrate_a_yearly_plan_to_a_non_recurring_plan_with_set_durat $activeSubscription = $this->user->active_subscription; $this->assertTrue($activeSubscription->is($newSubscription)); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(SubscriptionMigrated::class); } @@ -119,7 +116,6 @@ public function can_not_migrate_a_yearly_plan_to_a_non_recurring_plan_with_zero_ $this->user->migrateSubscriptionTo($durationPlan, false, true, 0); } catch (SubscriptionException $e) { $this->assertTrue($activeSubscription->is($oldSubscription)); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(SubscriptionMigrated::class); return; } @@ -146,7 +142,6 @@ public function cannot_migrate_a_testing_subscription_on_the_expiry_date(): void } catch (SubscriptionException $e) { $activeSubscription = $this->user->active_subscription; $this->assertTrue($activeSubscription->is($activeSubscription)); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(SubscriptionMigrated::class); return; } @@ -166,11 +161,32 @@ public function can_only_migrate_active_subscriptions(): void $this->user->migrateSubscriptionTo($monthlyPlan, true, false); } catch (SubscriptionException $e) { $this->assertFalse($this->user->hasActiveSubscription()); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(SubscriptionMigrated::class); return; } $this->fail(); } + + /** @test * + * @throws SubscriptionException + */ + public function migrations_to_free_plans_are_marked_as_paid(): void + { + $this->user->subscribeTo($this->plan, false, 30); + $oldsubscription = $this->user->active_subscription; + $this->assertEquals('yearly', $oldsubscription->plan->type); + $monthlyPlan = factory(Plan::class)->states('active', 'monthly')->create(['price' => 0]); + + Event::fake(); + $this->user->migrateSubscriptionTo($monthlyPlan, true, true); + + $subscription = $this->user->active_subscription; + $this->assertEquals('monthly', $subscription->plan->type); + $this->assertTrue($subscription->is_paid); + $this->assertEqualsWithDelta(Carbon::now(), $subscription->starts_at, 1); + Event::assertNotDispatched(NewSubscription::class); + Event::assertDispatched(SubscriptionMigrated::class); + } + } diff --git a/tests/feature/SubscribeTest.php b/tests/feature/SubscribeTest.php index af5c025..a7f4d95 100644 --- a/tests/feature/SubscribeTest.php +++ b/tests/feature/SubscribeTest.php @@ -40,12 +40,10 @@ public function can_subscribe_to_a_recurring_yearly_plan(): void /** @var Subscription $subscription */ $subscription = $this->user->active_or_last_subscription; $this->assertEqualsWithDelta(Carbon::now(), $subscription->starts_at, 1); - /** @noinspection PhpUndefinedMethodInspection */ $this->assertEqualsWithDelta(Carbon::now()->addYear()->endOfDay(), $subscription->expires_at, 1); $this->assertTrue($plan->is($subscription->plan)); $this->assertEquals($plan->price, $subscription->price); $this->assertEquals($plan->currency, $subscription->currency); - /** @noinspection PhpUndefinedMethodInspection */ $this->assertEquals(Carbon::now()->addYear()->diffInDays(Carbon::now()), $subscription->remaining_days); $this->assertTrue($subscription->is_recurring); @@ -54,11 +52,9 @@ public function can_subscribe_to_a_recurring_yearly_plan(): void $this->assertFalse($subscription->is_testing); $this->assertFalse($subscription->is_paid); $this->assertFalse($subscription->is_active); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(NewSubscription::class); $subscription->markAsPaid(); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(SubscriptionPaymentSucceeded::class); $this->assertTrue($subscription->fresh()->is_paid); $this->assertTrue($subscription->fresh()->is_active); @@ -74,14 +70,12 @@ public function can_subscribe_to_a_non_recurring_monthly_plan_with_test_period() $this->user->subscribeTo($plan, false,30); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(NewSubscription::class); $this->assertCount(1, $this->user->subscriptions); /** @var Subscription $subscription */ $subscription = $this->user->active_subscription; $this->assertTrue($plan->is($subscription->plan)); $this->assertEqualsWithDelta(Carbon::now()->addDays(30), $subscription->starts_at, 1); - /** @noinspection PhpUndefinedMethodInspection */ $this->assertEqualsWithDelta(Carbon::now()->addDays(30)->addMonth()->endOfDay(), $subscription->expires_at, 1); $this->assertFalse($subscription->is_recurring); $this->assertNull($subscription->refunded_at); @@ -105,14 +99,12 @@ public function can_subscribe_to_a_recurring_plan_with_set_duration(): void $subscription = $this->user->subscribeTo($plan, true,0, 10); $subscription->markAsPaid(); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertDispatched(NewSubscription::class); $this->assertCount(1, $this->user->subscriptions); /** @var Subscription $subscription */ $subscription = $this->user->active_subscription; $this->assertEqualsWithDelta(Carbon::now(), $subscription->starts_at, 1); $this->assertTrue($plan->is($subscription->plan)); - /** @noinspection PhpUndefinedMethodInspection */ $this->assertEqualsWithDelta(Carbon::now()->addDays(10)->endOfDay(), $subscription->expires_at, 1); $this->assertTrue($subscription->is_recurring); $this->assertNull($subscription->refunded_at); @@ -135,7 +127,6 @@ public function can_not_subscribe_to_a_plan_with_zero_day_duration(): void } catch (SubscriptionException $e) { $this->assertCount(0, $this->user->subscriptions); $this->assertCount(0, Subscription::all()); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(NewSubscription::class); return; } @@ -156,7 +147,6 @@ public function can_not_subscribe_overlapping_active_subscription(): void $this->assertCount(1, $this->user->subscriptions); /** @var Subscription $subscription */ $this->assertTrue($this->user->active_subscription->is($subscription)); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(NewSubscription::class); return; } @@ -177,10 +167,26 @@ public function can_not_subscribe_overlapping_other_future_subscription(): void $this->assertCount(1, $this->user->subscriptions); /** @noinspection PhpUndefinedVariableInspection */ $this->assertTrue($this->user->upcoming_subscription->is($subscription)); - /** @noinspection PhpUndefinedMethodInspection */ Event::assertNotDispatched(NewSubscription::class); return; } $this->fail('SubscriptionException expected'); } + + /** @test * + * @throws SubscriptionException + */ + public function subscriptions_for_free_plans_are_marked_as_paid(): void + { + Event::fake(); + $plan = factory(Plan::class)->states(['active', 'yearly'])->create(['price' => 0]); + $this->user->subscribeTo($plan); + Event::assertDispatched(NewSubscription::class); + $this->assertCount(1, $this->user->subscriptions); + /** @var Subscription $subscription */ + $subscription = $this->user->active_or_last_subscription; + + $this->assertTrue($subscription->fresh()->is_paid); + $this->assertTrue($subscription->fresh()->is_active); + } }