Skip to content

Instantly share code, notes, and snippets.

@fatso83
Created January 19, 2022 11:54
Show Gist options
  • Save fatso83/cde0c6dd53d84aa5c4ca85ed21fb66d1 to your computer and use it in GitHub Desktop.
Save fatso83/cde0c6dd53d84aa5c4ca85ed21fb66d1 to your computer and use it in GitHub Desktop.
A fixture example for Symfony where a hardcoded connection is made between a local entity and the Stripe id.
class PublicPlanData extends AbstractFixture implements OrderedFixtureInterface
{
public function load(ObjectManager $manager)
{
$planUnlimitedFree = new PlanInfo();
$planUnlimitedFree->setName('FREE UNLIMITED PLAN')
->setAmount(0)
->setCurrency('USD')
->setDescription('Special plan for users that should never pay for using the service')
->setType(PlanInfo::TYPE_FREE)
->setInterval(PlanInfo::INTERVAL_YEAR)
->setLicensesCount(0)
->setPublic(false)
->setId('62578588-5a55-4cea-911e-241ba1b3ce1c');
$manager->persist($planUnlimitedFree);
$planIndividualMonthly = new PlanInfo();
$planIndividualMonthly->setName('INDIVIDUAL MONTHLY PLAN')
->setAmount(1)
->setCurrency('USD')
->setDescription('INDIVIDUAL MONTHLY PLAN')
->setType(PlanInfo::TYPE_PERSONAL)
->setInterval(PlanInfo::INTERVAL_MONTH)
->setLicensesCount(1)
->setPublic(true)
->setId('32b1eff7-ca8a-4591-a537-a99f8c7a2edc'); // Stripe Test mode
$manager->persist($planIndividualMonthly);
$planIndividualYearly = new PlanInfo();
$planIndividualYearly->setName('INDIVIDUAL YEARLY PLAN')
->setAmount(1)
->setCurrency('USD')
->setDescription('INDIVIDUAL YEARLY PLAN')
->setType(PlanInfo::TYPE_PERSONAL)
->setInterval(PlanInfo::INTERVAL_YEAR)
->setLicensesCount(1)
->setPublic(true)
->setId('ac4e4771-1525-40e1-aa8f-019b9c2e3fb0'); // Stripe Test mode
$manager->persist($planIndividualYearly);
$manager->flush();
$this->addReference('plan-unlimited-free', $planUnlimitedFree);
$this->addReference('plan-individual-monthly', $planIndividualMonthly);
$this->addReference('plan-individual-yearly', $planIndividualYearly);
}
// This is the order in which the fixtures are created.
public function getOrder()
{
return 1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment