Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phpMick's avatar
Level 15

Test that db table has some rows?

Is there a good way to do this?

At the moment I am doing:

$this->seeInDatabase('things',['id' => 1]);

Mick

0 likes
2 replies
tykus's avatar

First off, I would not make assertions based on a hard-coded id, try to use other table attributes instead.

Whenever I have a test example like this, I would first assert that the record is not in the database:

$this->assertDatabaseMissing('things',['attribute' => $value]);

Then perform the action that you are testing, and afterwards assert that the database now has the record:

$this->assertDatabaseHas('things',['attribute' => $value]);

You can be confident that your action has created/updated that record.

If you were dealing with a specific model instance, you can also use the exists property to check if the object has been persisted or if it is just in memory:

$this->assertTrue($model->exists);
1 like
phpMick's avatar
Level 15

I'm starting with an empty table,

Then I have a function which pulls in an RSS feed and stores it in the table.

What would you do here?

I just want to check that I have some rows?

1 like

Please or to participate in this conversation.