'http://example.com' ]); $subscriber = Subscriber::create(); $subscriber->hydrate([ 'first_name' => 'John', 'last_name' => 'Mailer', 'email' => 'john@mailpoet.com' ]); $mailer = Stub::makeEmpty(Mailer::class, [ 'send' => Stub\Expected::once(function($email) { expect($email['body']['html'])->contains('Test segment'); expect($email['body']['html'])->contains('Click here to confirm your subscription.'); }), ], $this); $sender = new ConfirmationEmailMailer($mailer); $segment = Segment::createOrUpdate( array( 'name' => 'Test segment' ) ); SubscriberSegment::subscribeToSegments( $subscriber, array($segment->id) ); $sender->sendConfirmationEmail($subscriber); } function testItSetsErrorsWhenConfirmationEmailCannotBeSent() { $subscriber = Subscriber::create(); $subscriber->hydrate([ 'first_name' => 'John', 'last_name' => 'Mailer', 'email' => 'john@mailpoet.com' ]); $mailer = Stub::makeEmpty(Mailer::class, [ 'send' => Stub\Expected::once(function () { throw new \Exception('send error'); }), ], $this); $sender = new ConfirmationEmailMailer($mailer); $sender->sendConfirmationEmail($subscriber); // error is set on the subscriber model object expect($subscriber->getErrors()[0])->equals('send error'); } function _after() { \ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); \ORM::raw_execute('TRUNCATE ' . Segment::$_table); \ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table); } }