Download the PHP package czukowski/phpunit-sql without Composer

On this page you can find all versions of the php package czukowski/phpunit-sql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpunit-sql

SQL strings testing for PHPUnit

PHPUnit

A constraint and assert method for testing SQL strings equality while ignoring whitespace. Can be useful for testing results of query builders (especially those for long and complex queries) against well-formatted 'expected' queries stored in files.

This does not replace the need to verify that the queries actually do the intended job.

Installation

Pick your version! Version numbering follows major PHPUnit version numbers, so for a given PHPUnit N.x, the installation command would look like this:

Usage

Use Cz\PHPUnit\SQL\AssertTrait trait in a test case class, this will enable methods for comparing SQL queries equality equal except for space and a terminal semicolon. An SQL query may be denoted as strings or objects castable to strings. Arrays of SQL queries are also acceptable and can be used to compare series of queries. For the purposes of the comparison, array with a single SQL query element is equal to the SQL query element itself, so there's no need to remember to eg. convert arguments to arrays all the time.

  1. assertEqualsSQLQueries method will verify equality of two queries or series of queries.

  2. assertExecutedSQLQueries method will verify that a query or a series of queries has been executed by a database abstraction layer. In order to be able to do it, a getDatabaseDriver method must be implemented by the test case class, that returns an object implementing the Cz\PHPUnit\SQL\DatabaseDriverInterface interface. That can be a database abstraction layer connection class with a fake database driver or something, which is injected into the tested application code.

    The interface implementation is available in Cz\PHPUnit\SQL\DatabaseDriverTrait for easy inclusion into custom implementations.

  3. loadSQLQueries method will load SQL query or a series thereof from a file and return an array of queries. Splitting of queries by a delimiter ; works only if the next query after a delimiter starts from the following line. Other than that, there may be newlines and blank lines inside the queries and in between of them, they do not get removed on load. By default, the method looks for the file in a subfolder named after the file name of the current class (presumably test case). That behavior can be changed by overriding getLoadFilePath method.

    The assertion methods will flatten arrays of queries, so multiple files may be loaded without a need to process them further.

Does not match your specific needs? No problem, the AssertTrait is extremely simple, you can clone and adjust it for your project or come up with a completely different implementation.

Known issues

In order to compare SQL queries, a rather naive tokenizer function is used to convert query strings to arrays. It may not cover some edge cases when uncommon operators or SQL syntax is used in queries (specifically DDL was not tested), but it should be fairly easy to fix.

License

This work is released under the MIT License. See LICENSE.md for details.


All versions of phpunit-sql with dependencies

PHP Build Version
Package Version
Requires phpunit/phpunit Version ~9.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package czukowski/phpunit-sql contains the following files

Loading the files please wait ....