{"id":21722694,"url":"https://github.com/czukowski/phpunit-sql","last_synced_at":"2026-05-09T13:07:37.652Z","repository":{"id":56961080,"uuid":"123493661","full_name":"czukowski/phpunit-sql","owner":"czukowski","description":"SQL strings testing helpers for PHPUnit","archived":false,"fork":false,"pushed_at":"2020-12-21T14:15:49.000Z","size":54,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-08-23T04:51:23.444Z","etag":null,"topics":["phpunit","sql"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/czukowski.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-01T21:19:53.000Z","updated_at":"2020-12-21T13:35:39.000Z","dependencies_parsed_at":"2022-08-21T09:20:56.216Z","dependency_job_id":null,"html_url":"https://github.com/czukowski/phpunit-sql","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/czukowski/phpunit-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czukowski%2Fphpunit-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czukowski%2Fphpunit-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czukowski%2Fphpunit-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czukowski%2Fphpunit-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/czukowski","download_url":"https://codeload.github.com/czukowski/phpunit-sql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czukowski%2Fphpunit-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32820266,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["phpunit","sql"],"created_at":"2024-11-26T02:32:00.943Z","updated_at":"2026-05-09T13:07:37.614Z","avatar_url":"https://github.com/czukowski.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"SQL strings testing for PHPUnit\n===============================\n\n![PHPUnit](https://github.com/czukowski/phpunit-sql/workflows/PHPUnit/badge.svg)\n\nA constraint and assert method for testing SQL strings equality while ignoring whitespace.\nCan be useful for testing results of query builders (especially those for long and complex\nqueries) against well-formatted 'expected' queries stored in files.\n\nThis does not replace the need to verify that the queries actually do the intended job.\n\nInstallation\n------------\n\nPick your version! Version numbering follows major PHPUnit version numbers, so for a given\nPHPUnit N.x, the installation command would look like this:\n\n```sh\ncomposer require czukowski/phpunit-sql \"~N.0\"\n```\n\nUsage\n-----\n\nUse `Cz\\PHPUnit\\SQL\\AssertTrait` trait in a test case class, this will enable methods for\ncomparing SQL queries equality equal except for space and a terminal semicolon. An SQL query\nmay be denoted as strings or objects castable to strings. Arrays of SQL queries are also\nacceptable and can be used to compare series of queries. For the purposes of the comparison,\narray with a single SQL query element is equal to the SQL query element itself, so there's\nno need to remember to eg. convert arguments to arrays all the time.\n\n1. `assertEqualsSQLQueries` method will verify equality of two queries or series of queries.\n   \n   ```php\n   $this-\u003eassertEqualsSQLQueries($expected, $actual);\n   ```\n\n2. `assertExecutedSQLQueries` method will verify that a query or a series of queries has been\n   executed by a database abstraction layer. In order to be able to do it, a `getDatabaseDriver`\n   method must be implemented by the test case class, that returns an object implementing the\n   `Cz\\PHPUnit\\SQL\\DatabaseDriverInterface` interface. That can be a database abstraction layer\n   connection class with a fake database driver or something, which is injected into the tested\n   application code.\n   \n   ```php\n   $this-\u003eassertExecutedSQLQueries($expected);\n   ```\n   \n   The interface implementation is available in `Cz\\PHPUnit\\SQL\\DatabaseDriverTrait` for easy\n   inclusion into custom implementations.\n\n3. `loadSQLQueries` method will load SQL query or a series thereof from a file and return an\n   array of queries. Splitting of queries by a delimiter `;` works only if the next query after\n   a delimiter starts from the following line. Other than that, there may be newlines and blank\n   lines inside the queries and in between of them, they do not get removed on load. By default,\n   the method looks for the file in a subfolder named after the file name of the current class\n   (presumably test case). That behavior can be changed by overriding `getLoadFilePath` method.\n   \n   ```php\n   $this-\u003eloadSQLQueries($expected);\n   ```\n   \n   The assertion methods will flatten arrays of queries, so multiple files may be loaded without\n   a need to process them further.\n   \n   ```php\n   $this-\u003eassertExecutedSQLQueries([\n       $this-\u003eloadSQLQueries('SelectItems.sql'),\n       $this-\u003eloadSQLQueries('InsertNewItems.sql'),\n       $this-\u003eloadSQLQueries('DeleteOldItems.sql'),\n   ]);\n   ```\n\n**Does not match your specific needs?** No problem, the `AssertTrait` is extremely simple, you can\nclone and adjust it for your project or come up with a completely different implementation.\n\nKnown issues\n------------\n\nIn order to compare SQL queries, a rather naive tokenizer function is used to convert query\nstrings to arrays. It may not cover some edge cases when uncommon operators or SQL syntax is\nused in queries (specifically DDL was not tested), but it should be fairly easy to fix.\n\nLicense\n-------\n\nThis work is released under the MIT License. See LICENSE.md for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczukowski%2Fphpunit-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fczukowski%2Fphpunit-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczukowski%2Fphpunit-sql/lists"}