====== Unit Testing ======
This feature is in initial development. Feature may change substantially at any time
Unit testing can be done using PHPUnit testing. Testing can be done against any database that is available that you have admin rights on. The test creates tables, populates them with small amounts of data and drops them.
===== Prerequistes =====
* PHP 8.0 or higher
* [[https://phpunit.de|PHPUnit]] Version 9 or higher must be installed to conduct the suite of tests.
===== Setup =====
Configuration information for the tests is held in a configuration file //**adodb-unittest.ini**//. The file can be located anywhere in the PHP include path.
===== Settup Up The Configuration File =====
==== ADOdb Section ====
If the ADOdb section is defined, and the item directory is set, the tests can be run against any ADOdb installation set locally. This is useful if ADOdb is embedded into a different application
[ADOdb]
directory=/opt/some/local/ADOdb/installation
If the section is not defined, it assumes that the ADOdb installation is the parent directory of the unit test
/opt/ADOdb
/opt/ADOdb/unittest
==== Blob Section ====
This section must be defined with the path name of a binary file, such as a jpeg file that can be used for read-write testing. If set to false, all blob tests are skipped.
[blob]
testBlob=c:/temp/someJpeg.jpg
==== XMLschema Section ====
This section must be explicitly enabled in the configuration file, with the skipXmlTests value set to 0 , otherwise all tests in the section are skipped. Setting the value to 1 will also skip the tests
[xmlschema]
skipXmlTests=0
==== Driver Section ====
The driver configuration is based on the driver name. You can add as many drivers to the configuration file as you want. Only the driver specified on the command line or the first driver found in the configuration file flagged //**active**// is tested.
[mysqli]
dsn=
host=mysql-server.com
user=root
password=somepassword
database=adodb-tester
debug=0
parameters=
active=1
^Setting^Description^
|dsn|Either use a connection DSN or specify the parameters usual|
|host|The hostname associated with the database|
|user|The connection username|
|password|The connection password|
|debug|Sets the debug mode|
|parameters|To set parameters normally set by ''setConnectionParameter()'', create a string in format **key=value;** Note that the parameters cannot be defined as constants, you must use the numeric or string equivalents|
|active|If a run-time parameter of the driver is not passed of the PHPunit version > 9, then the test is run against the first driver where the active flag is set to true|
==== Meta Section ====
Unless explicitly enabled, the test to create a new database using the //**createDatabase**// method is skipped as it requires CREATE DATABASE privilege on the DBMS. To enable this test, set the following section:
[meta]
skipDbCreation=0
==== Caching Section ====
Unless explicitly enabled, cache functions such as //**CacheExecute()**// are skipped. Tests are supported using Filesystem based or memcache based caching. To activate this, add the following section to adodb-unittest.ini:
=== Filesystem ===
[caching]
cacheMethod=1
cacheDir=c:/dev/cache
=== Memcache Based ===
[cache]
cacheMethod=2
cacheHost=192.168.1.50
To disable cache tests while leaving the section in place, ''set cacheMethod=0''
==== Globals Section ====
To test some date functions, the local timezone must be equal to the server timezone. To change the timezone temporarily for the test, set the following gloval parameter in adodb-unittest.ini. This should exactly match the format in php.ini.
[globals]
date.timezone = 'America/Denver'
Any parameter saved into the **[globals]** section will be set using ini_set()
===== Test Execution =====
==== PHPUnit Version 9 ====
phpunit unittest --bootstrap unittest/dbconnector.php
Where the name represents the ADOdb driver to use. For use of PDO drivers use the format pdo-. The driver name **__must__** follow the bootstrap file name
==== PHPUnit 10 or higher ====
phpunit unittest --bootstrap unittest/dbconnector.php
It is not possible to pass the driver name as a run-time argument in this version. The driver to test must have the **active** flag defined in the driver section.
===== Writing or Updating Tests =====
* Tests should be compliant with PHPunit version 9 and higher
* Tests should be compatible with all platforms supported by PHPunit
* Tests should be written to [[https://www.php-fig.org/psr/psr-12/|PSR 12]] standards when possible
* Wherever possible, write database agnostic tests. Only write driver specific tests when a feature is only supported by one or two DBMS
* Only add driver specific tests to the test file specifically labeled for that driver, e.g. //**MysqliDriverTest.php**//
* Do not add driver-based code branches inside the generic test code