Skip to content

test: add SQL equality assertion helper#10299

Open
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/assert-sql-equals
Open

test: add SQL equality assertion helper#10299
memleakd wants to merge 1 commit into
codeigniter4:4.8from
memleakd:feat/assert-sql-equals

Conversation

@memleakd

Copy link
Copy Markdown
Contributor

Description

This PR adds assertSqlEquals() to CIUnitTestCase.

This follows up on @datamweb's suggestion to introduce this helper.

The helper keeps a small pattern we already use in many Query Builder tests in one place:

$this->assertSqlEquals($expected, $builder->getCompiledSelect());

It intentionally stays conservative and only ignores newlines in the actual SQL. It does not lowercase, trim, or normalize whitespace more broadly, so SQL assertions remain strict while avoiding the repeated str_replace("\n", ' ', ...) calls.

I also updated the testing docs and converted a few representative Query Builder assertions to show the intended usage. Broader migration of existing SQL assertions can happen separately after the helper is available.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

- Add assertSqlEquals() to CIUnitTestCase
- Document the helper in the testing guide
- Use the helper in representative Query Builder tests

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>
@github-actions github-actions Bot added the 4.8 PRs that target the `4.8` branch. label Jun 11, 2026

@datamweb datamweb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@memleakd Thanks! LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.8 PRs that target the `4.8` branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants