Summer Sale! All accounts are 50% off this week.

oroalej's avatar

Check if timestamp column has value

Hi all, I'm trying to test if a specific column in a table was filled after I did a specific operation.

I have a archived_at timestamp column that will be filled when user accessed the archived API. Now, I'm creating a test case to check if this column is filled. Since this is a timestamp, I don't know the actual data that was saved in the database. Hence, assertDatabaseHas always fails.

For now what I'm doing is just refresh the model I got using $model->refresh() and using the data from there to compare it in assertDatabaseHas. Not sure if this is the best approach of it.

Really appreciate your suggestions.

UPDATE: What I just did was $this->assertNotNull($model->transaction_date)

0 likes
2 replies
vincent15000's avatar

Are you writing tests to test if your app works correctly or do you only need to check inside the code if a timestamp column has a value ?

Tray2's avatar

The easiest way to check that is to use IS NULL or IS NOT NULL in your queries.

SELECT *
FROM table1
WHERE column1 IS NULL;
1 like

Please or to participate in this conversation.