Skip to content

Commit

Permalink
Add test to check if it allows previous values to be read
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkleemans committed Aug 21, 2024
1 parent 407aa25 commit a8d74ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/AttributeEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,22 @@ public function test_it_ignores_non_matching_enums()
$this->dispatcher->assertNotDispatched(Fake\Events\EnumOrderShipped::class);
}

public function test_it_allows_previous_values_to_be_read()
{
$order = new Fake\Order();
$order->note = 'Please handle with care';
$order->save();

$order = Fake\Order::find($order->id);
$order->note = 'Please deliver to neighbour';
$order->save();

$this->dispatcher->assertDispatched(function (Fake\Events\OrderNoteUpdated $event) {
return $event->oldValue === 'Please handle with care'
&& $event->newValue === 'Please deliver to neighbour';
});
}

// Setup methods

private function initEventDispatcher()
Expand Down
5 changes: 5 additions & 0 deletions tests/Fake/Events/OrderNoteUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

class OrderNoteUpdated
{
public $oldValue;
public $newValue;

public function __construct(Order $order)
{
$this->oldValue = $order->getOriginal('note');
$this->newValue = $order->note;
}
}

0 comments on commit a8d74ae

Please sign in to comment.