Skip to content

Commit

Permalink
wrong object passed (closes #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
edalzell committed Jul 30, 2020
1 parent f37b28f commit 3b2123c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Listeners/AddFromSubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
namespace Edalzell\Mailchimp\Listeners;

use Edalzell\Mailchimp\Subscriber;
use Statamic\Forms\Submission;
use Statamic\Events\SubmissionCreated;

class AddFromSubmission
{
public function handle(Submission $submission)
public function handle(SubmissionCreated $event)
{
$subscriber = new Subscriber($submission->data(), $this->formConfig($submission->form()->handle()));
$subscriber = new Subscriber($event->submission->data(), $this->formConfig($event->submission->form()->handle()));
$subscriber->subscribe();
}

Expand Down
15 changes: 5 additions & 10 deletions tests/Unit/ListenersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Event;
use Statamic\Events\SubmissionCreated;
use Statamic\Facades\Form as FormAPI;
use Statamic\Fields\Blueprint;
use Statamic\Forms\Form as Form;
use Statamic\Forms\Submission;

Expand All @@ -22,28 +21,24 @@ public function setUp(): void

FormAPI::all()->each->delete();

$blueprint = (new Blueprint)->setHandle('post')->save();

$this->form = FormAPI::make('contact_us')
->title('Contact Us')
->blueprint($blueprint)
->honeypot('winnie');

$this->form->save();

$this->submission = $this->form->createSubmission();
$this->submission = $this->form->makeSubmission();
$this->submission
->unguard()
->data(['foo'=>'bar']);
}

/** @test */
public function does_respond_to_events()
{
$this->mock(AddFromSubmission::class, function ($mock) {
$mock->shouldReceive('handle')->once();
});
$event = new SubmissionCreated($this->submission);

$this->mock(AddFromSubmission::class)->shouldReceive('handle')->with($event)->once();

Event::dispatch(SubmissionCreated::class, $this->submission);
Event::dispatch($event);
}
}
7 changes: 1 addition & 6 deletions tests/Unit/SubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Edalzell\Mailchimp\Subscriber;
use Edalzell\Mailchimp\Tests\TestCase;
use Statamic\Facades\Form as FormAPI;
use Statamic\Fields\Blueprint;
use Statamic\Forms\Form as Form;
use Statamic\Forms\Submission;

Expand All @@ -20,18 +19,14 @@ public function setUp(): void

FormAPI::all()->each->delete();

$blueprint = (new Blueprint)->setHandle('post')->save();

$this->form = FormAPI::make('contact_us')
->title('Contact Us')
->blueprint($blueprint)
->honeypot('winnie');

$this->form->save();

$this->submission = $this->form->createSubmission();
$this->submission = $this->form->makeSubmission();
$this->submission
->unguard()
->data(['foo'=>'bar']);
}

Expand Down

0 comments on commit 3b2123c

Please sign in to comment.