Skip to content

Commit

Permalink
feat: add query string assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
yalsicor committed Sep 15, 2024
1 parent 8dd7f13 commit f441005
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Traits/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ protected function assertDatabaseQueryCount(int $expectedCount): void
$this->assertEquals($expectedCount, $actualCount, "Expected $expectedCount database queries, but got $actualCount.");
}

/**
* Assert that the database queries contain the expected query.
*/
protected function assertDatabaseQueriesContains(string $expectedQuery): void
{
$queries = $this->getDatabaseQueries();

$found = false;
foreach ($queries as $query) {
if (str_contains($query['query'], $expectedQuery)) {
$found = true;
break;
}
}

$this->assertTrue($found, "Expected query '$expectedQuery' not found in database queries.");
}

/**
* Wrapper to profile database queries.
*/
Expand Down

0 comments on commit f441005

Please sign in to comment.