/** * Verify that a plan with a given ID exists, or create a new one if it does * not. */ protected static function retrieveOrCreatePlan($id) { self::authorizeFromEnv(); try { $plan = Plan::retrieve($id); } catch (Error\InvalidRequest $exception) { $plan = Plan::create(array('id' => $id, 'amount' => 0, 'currency' => 'usd', 'interval' => 'month', 'name' => 'Gold Test Plan')); } }
public function testSave() { self::authorizeFromEnv(); $planID = 'gold-' . self::generateRandomString(20); $p = Plan::create(array('amount' => 2000, 'interval' => 'month', 'currency' => 'usd', 'name' => 'Plan', 'id' => $planID)); $p->name = 'A new plan name'; $p->save(); $this->assertSame($p->name, 'A new plan name'); $stripePlan = Plan::retrieve($planID); $this->assertSame($p->name, $stripePlan->name); }
public function run() { // Create a new instance of Faker $faker = Faker\Factory::create(); // Create a plan $plan = Plan::create(['user_id' => 2]); // Attach an instructor //$plan->instructors()->attach(1); // Create some goals $goals = [new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')]), new Goal(['plan_id' => 1, 'title' => ucwords(implode(' ', $faker->words(mt_rand(4, 10)))), 'summary' => $faker->text(mt_rand(25, 200)), 'created_at' => $faker->dateTimeBetween('-1 years'), 'updated_at' => $faker->dateTimeBetween('-1 years')])]; // Attach the goals to the plan $plan->goals()->saveMany($goals); // Create some comments for ($i = 0; $i < 15; $i++) { $date = $faker->dateTimeBetween('-1 years'); Comment::create(['goal_id' => mt_rand(1, 4), 'user_id' => mt_rand(1, 2), 'content' => $faker->text(mt_rand(10, 300)), 'created_at' => $date, 'updated_at' => $date]); } }