Skip to content

Commit

Permalink
Adds failing test for savepoint and observers using afterCommit
Browse files Browse the repository at this point in the history
  • Loading branch information
tonysm committed Sep 20, 2023
1 parent 1f10b5e commit d9538d6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/Database/DatabaseEloquentAppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ public function testObserverCalledWithAfterCommitWhenInsideTransaction()
$this->assertTrue($user1->exists);
$this->assertEquals(1, $observer::$calledTimes, 'Failed to assert the observer was called once.');
}

public function testObserverIsCalledOnTestsWithAfterCommitWhenUsingSavepoint()
{
DatabaseEloquentAppTestUser::observe($observer = DatabaseEloquentAppTestUserObserver::reseting());

$user1 = DatabaseEloquentAppTestUser::createOrFirst([
'email' => '[email protected]',
]);

$this->assertTrue($user1->exists);
$this->assertEquals(1, $observer::$calledTimes, 'Failed to assert the observer was called once.');
}

public function testObserverIsCalledOnTestsWithAfterCommitWhenUsingSavepointAndInsideTransaction()
{
DatabaseEloquentAppTestUser::observe($observer = DatabaseEloquentAppTestUserObserver::reseting());

$user1 = DB::transaction(fn () => DatabaseEloquentAppTestUser::createOrFirst([
'email' => '[email protected]',
]));

$this->assertTrue($user1->exists);
$this->assertEquals(1, $observer::$calledTimes, 'Failed to assert the observer was called once.');
}
}

class DatabaseEloquentAppTestUser extends Model
Expand Down

0 comments on commit d9538d6

Please sign in to comment.