flo

How to test commands

Posted 4 years ago by flo

Currently I'm trying to find out what the best way would be to test a command.

I have tried creating an example below. But I'm clueless on how to test this whole process to make sure this functionality will always work.

// SubscribersController@store
$this->execute(SignupSubscriberCommand::class);
// SignupSubscriberCommandHandler@handle
$subscriber = Subscriber::signup($command->mailinglistId, $command->email);

$this->dispatchEventsFor($subscriber);

return $subscriber;
// Subscriber@signup (Eloquent model)
$confirmation_code = str_random(32);

$subscriber = static::create(compact('mailinglist_id', 'email', 'confirmation_code'));

$subscriber->raise(new SubscriberWasSignedUp($subscriber));

return $subscriber;
// EmailNotifier@whenSubscriberWasSignedUp
$subscriber = $event->subscriber;

$data = [
      'subscriber' => $subscriber,
];

$mail = Mail::send('emails.subscribers.signup', $data, function($m) use ($subscriber){
    $m->to($subscriber->email)
    ->subject('Confirm your subscription');
});

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.