I have a simple functional test for a registration using the L4 module, everything works except my newly added feature of automatically creating the username from the email address. Basically in my User model I have this:
public static function boot()
{
parent::boot();
// Automatically generate the user's username from their email address
static::creating(function($user)
{
$user->username = preg_replace("/(@.+)|[^A-Za-z0-9]/", "", $user->email);
});
}
This works just fine in the browser, but in my test I get an error:
1) Failed to register a new account in Users/RegisterCept
Couldn't click "Create Account":
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 19 users.username may not be NULL (SQL: insert into "users" ("first_name", "last_name", "email", "password", "updated_at", "created_at") values (John, Doe, john.doe@example.com, y$McoL9XKY8SHBaxoDAhMa0OjMdLYzHUW5O3rsPp0q.C5Wd2qew5M/W, 2014-10-01 20:23:48, 2014-10-01 20:23:48))
It's as if the creating() event isn't being fired.
Any ideas?