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
// SignupSubscriberCommandHandler@handle
$subscriber = Subscriber::signup($command->mailinglistId, $command->email);


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){
    ->subject('Confirm your subscription');

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

Reply to

Use Markdown with GitHub-flavored code blocks.