5

I am running laravel dusk tests.

I am trying to determine whether the database has a record which contains a string.

Eloquent has a wildcard where clause that performs this activity.

i.e. 'like', '%' . $stringToSearch . '%'

I am trying to find a syntax that performs the same comparison with assertDatabaseHas in my dusk browser tests.

Standard where query...

$this->assertDatabaseHas('tableName',['TableField' => 'stringToFind']);

Query i would like to think exists...

$this->assertDatabaseHas('tableName',['TableField' => 'like', '%' . $stringToSearch . '%']);
Regolith
  • 2,944
  • 9
  • 33
  • 50
Greenie
  • 113
  • 1
  • 11

1 Answers1

0

The way the assertDatabaseHas() function works is that the 2nd argument ['TableField' => 'stringToFind'] is passed to an Illuminate QueryBuilder's ->where() function so you end up in

->where(['TableField' => 'stringToFind'])

Because of this you can do the following:

$this->assertDatabaseHas('tableName',['TableField', 'LIKE', "%{$stringToSearch}%"]);

and achieve what you want

Daniel
  • 10,641
  • 12
  • 47
  • 85