Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Tests\Controller;
- use DateTime;
- use App\Entity\User;
- use App\Entity\Subscription;
- use Doctrine\ORM\EntityManagerInterface;
- use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
- class WebhookControllerTest extends WebTestCase
- {
- /** @var EntityManagerInterface */
- private $em;
- public function setUp()
- {
- self::bootKernel();
- $this->em = self::$container->get('doctrine');
- }
- public function testStripeCustomerSubscriptionDeleted()
- {
- $subscription = $this->createSubscription();
- $eventJson = $this->getCustomerSubscriptionDeletedEvent($subscription->getStripeSubscriptionId());
- $client = $this->createClient();
- $client->request(
- 'POST',
- 'webhooks/stripe',
- [],
- [],
- [],
- $eventJson
- );
- dump($client->getResponse()->getContent());
- $this->assertEquals(200, $client->getResponse()->getStatusCode());
- $this->assertFalse($subscription->isActive());
- }
- private function createSubscription()
- {
- $user = new User();
- $user->setEmail('fluffy'.mt_rand().'@sheep.com');
- $user->setUsername('fluffy'.mt_rand());
- $user->setPassword("password");
- $subscription = new Subscription();
- $subscription->setUser($user);
- $subscription->activateSubscription(
- 'plan_STRIPE_TEST_ABC'.mt_rand(),
- 'sub_STRIPE_TEST_XYZ'.mt_rand(),
- new \DateTime('+1 month')
- );
- $this->em->persist($user);
- $this->em->persist($subscription);
- $this->em->flush();
- return $subscription;
- }
- private function getCustomerSubscriptionDeletedEvent($subscriptionId)
- {
- $json = <<<EOF
- {
- //...
- }
- EOF;
- return sprintf($json, $subscriptionId);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement