Inheritance: extends Illuminate\Support\Collection
 public function setUp()
 {
     $this->mailChimpApi = Mockery::mock(MailChimp::class);
     $this->mailChimpApi->shouldReceive('getLastError')->andReturn(false);
     $newsletterLists = NewsletterListCollection::createFromConfig(['lists' => ['list1' => ['id' => 123], 'list2' => ['id' => 456]], 'defaultListName' => 'list1']);
     $this->newsletter = new Newsletter($this->mailChimpApi, $newsletterLists);
 }
 public function register()
 {
     $this->app->singleton(Newsletter::class, function () {
         $mailChimp = new Mailchimp(config('laravel-newsletter.apiKey'));
         $mailChimp->verify_ssl = config('laravel-newsletter.ssl', true);
         $configuredLists = NewsletterListCollection::createFromConfig(config('laravel-newsletter'));
         return new Newsletter($mailChimp, $configuredLists);
     });
     $this->app->alias(Newsletter::class, 'laravel-newsletter');
 }
Example #3
0
 /**
  * @param string $fromName
  * @param string $replyTo
  * @param string $subject
  * @param string $html
  * @param string $listName
  * @param array  $options
  * @param array  $contentOptions
  *
  * @return array|bool
  *
  * @throws \Spatie\Newsletter\Exceptions\InvalidNewsletterList
  */
 public function createCampaign($fromName, $replyTo, $subject, $html = '', $listName = '', $options = [], $contentOptions = [])
 {
     $list = $this->lists->findByName($listName);
     $defaultOptions = ['type' => 'regular', 'recipients' => ['list_id' => $list->getId()], 'settings' => ['subject_line' => $subject, 'from_name' => $fromName, 'reply_to' => $replyTo]];
     $options = array_merge($defaultOptions, $options);
     $response = $this->mailChimp->post('campaigns', $options);
     if (!$this->lastActionSucceeded()) {
         return false;
     }
     if ($html === '') {
         return $response;
     }
     if (!$this->updateContent($response['id'], $html, $contentOptions)) {
         return false;
     }
     return $response;
 }
 /** @test */
 public function it_will_throw_an_exception_when_using_a_default_list_that_does_not_exist()
 {
     $this->setExpectedException(InvalidNewsletterList::class);
     $newsletterListCollection = NewsletterListCollection::createFromConfig(['lists' => ['list1' => ['id' => 'list1']], 'defaultListName' => 'list2']);
     $newsletterListCollection->findByName('');
 }