public static function submit(RegistrationRequestId $id, FullName $fullName, Gender $gender, DateTimeImmutable $birthdate, ContactInfo $contact, StudyDetails $studyDetails, PaymentInfo $paymentInfo = null) : RegistrationRequest { $request = new RegistrationRequest(); $request->apply(new RegistrationRequestSubmitted($id, $fullName, $gender, $birthdate, $contact, $studyDetails)); if (isset($paymentInfo)) { $request->providePaymentInfo($paymentInfo); } return $request; }
/** @test */ public function a_visitor_can_request_to_be_registered() { $id = RegistrationRequestId::generate(); $this->scenario->when(function () use($id) { return RegistrationRequest::submit($id, new FullName('Mark', '', 'Redeman'), Gender::fromString('male'), new DateTimeImmutable('1993-04-26'), ContactInfo::describe(new Email('*****@*****.**'), new Address('Groningen', '9742GS', 'Plutolaan 11')), new StudyDetails('Msc Applied Mathematics', new DateTimeImmutable('2011-09-01'), 's2218356'), new PaymentInfo(true, true)); })->then([new RegistrationRequestSubmitted($id, new FullName('Mark', '', 'Redeman'), Gender::fromString('male'), new DateTimeImmutable('1993-04-26'), ContactInfo::describe(new Email('*****@*****.**'), new Address('Groningen', '9742GS', 'Plutolaan 11')), new StudyDetails('Msc Applied Mathematics', new DateTimeImmutable('2011-09-01'), 's2218356')), new PaymentInfoProvided($id, new PaymentInfo(true, true))]); }
/** * Run the database seeds. * * @return void */ public function run() { $repo = App::make(Repository::class); $faker = App::make(Faker\Generator::class); $genders = ['male', 'female']; for ($i = 0; $i < 10; $i++) { $id = RegistrationRequestId::generate(); $gender = $faker->randomElement($genders); $request = RegistrationRequest::submit($id, new FullName($faker->firstName($gender), '', $faker->lastName), Gender::fromString($gender), DateTimeImmutable::createFromMutable($faker->dateTimeInInterval('- 30 years', '-16 years')), ContactInfo::describe(new Email($faker->safeEmail), new Address($faker->city, $faker->postCode, $faker->streetAddress)), new StudyDetails('Msc Applied Mathematics', new DateTimeImmutable('2011-09-01'), 's2218356'), new PaymentInfo(true, $faker->boolean)); $repo->save($request); } }
public function handle(Repository $repo) { $registrationRequest = RegistrationRequest::submit($this->id, $this->name, $this->gender, $this->birthdate, $this->contactInfo, $this->study, $this->paymentInfo); $repo->save($registrationRequest); }