From f4410059e8e9bb2d24aba0ec1f6b5aed13cb2b55 Mon Sep 17 00:00:00 2001 From: Sebastian Weckend Date: Sun, 15 Sep 2024 19:24:25 +0200 Subject: [PATCH] feat: add query string assertion --- .../PhpUnit/TestDatabaseProfilerTrait.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Traits/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php b/src/Traits/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php index eadf3f04..2b3377ea 100644 --- a/src/Traits/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php +++ b/src/Traits/TestTraits/PhpUnit/TestDatabaseProfilerTrait.php @@ -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. */