| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | no
| Framework | Laravel
| Framework version | 5.4
| Package version | 3.1
| PHP version | 7.1
I need to update the package but wanted to make sure i don't break things. So i'm adding a few functional tests to verify that audits are working so that when i make the migration it should be easy to tell what breaks.
Right now i have a very simple test
private function createEmployee($params, $user = null)
{
$permission = new Permission();
$permission->name = 'create-employee';
$permission->save();
if ($user == null) {
$user = factory(User::class)->create();
}
$user->attachPermission($permission);
$response = $this->actingAs($user)->json('POST', '/employees', $params);
return $response;
}
/** @test */
public function creating_employee_record_adds_audits()
{
$user = factory(User::class)->create();
$input = [
"f_name" => "First Name",
"l_name" => "Last Name"
];
$response = $this->createEmployee($input);
$response->assertStatus(200);
$employee = Employee::find($response->json()['id']);
dd($employee->audits);
}
The problem i'm having is that the audits return empty collection, if i just do a simple $this-> assertDatabaseHas('audits', ['user_id'=>$user->id]); that will return an audits table is empty response. So it looks like when i submit the data to the endpoint it isn't triggering the audit.
It's also worth mentioning that this package works just fine outside of PHPUnit
able to get back audit data and see that the table has audit data
I suspect it's my lack of testing experience, so to avoid spamming this with a bunch of useless code i'll just show my controller code, if you need other bits just let me know, but as i mentioned before it works just fine outside of PHPUnit
public function store(CreateEmployeeRequest $request)
{
$employee = Employee::create($request->all());
$employee->save();
Flash::success('Employee saved successfully.');
return $employee;
}
Anywhos, hopefully you can see the errors of my ways and point me in the right direction
Thanks,
Jeff
I swear you always figure out your issue after you click the submit button...
Anyways for anyone else who stumbles on this, my solution was to add
audit_console' => true,
to the config/audit.php file
Is there a way to change config in the test?
config(['audit.console' => true]); is not working
Is there a way to change config in the test?
config(['audit.console' => true]);is not working
try
config()->set('audit.console', true);
Most helpful comment
I swear you always figure out your issue after you click the submit button...
Anyways for anyone else who stumbles on this, my solution was to add
to the
config/audit.phpfile