Observer not firing

Posted 4 months ago by Danieloplata

Hi

I've set up 2 observers for my project, one is firing normally and the other doesn't appear to be firing at all..

AppServiceProvider.php

use App\Project;
use App\Panel;
...

public function boot()
{
    Project::observe(ProjectObserver::class);
    Panel::observe(PanelObserver::class);
}

PanelObserver.php

use App\Panel;
use App\Activity;
...

public function created(Panel $panel)
{
    Activity::create([
        'project_id' => $panel->project->id, // $panel->project->id is returning correct #
        'description' => 'panel_created'
    ]);
}

PHPUnit test:

public function setUp() 
{
    parent::setup();
    $this->be($user = factory('App\User')->create());
    $this->project = factory('App\Project')->create();
    $this->panel = factory('App\Panel')->create(['project_id' => $this->project->id]);
}

/** @test */
function creating_a_panel_generates_activity()
{
    $this->assertCount(2, $this->panel->project->activity);
    $this->assertEquals('panel_created', $this->panel->project->activity->last()->description);
}

Error:

Failed asserting that actual size 1 matches expected size 2.

We should have 2 records in the Activity, from the creation of the Project and the creation of the Panel. The Panel creation isn't being recorded, while the Project is.

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