Skip to content

Commit 2319805

Browse files
photodudembabker
authored andcommitted
Add AppVeyor CI support (joomla#72)
* Create phpunit.appveyor.xml the php unit file for app veyor DSN items * Create appveyor.yml First draft of the appveyor configuration * Rename appveyor.yml to .appveyor.yml * need PDO drivers in php.ini * try host and password change * try without password * try absolute path * revert absolute path * Add PHP info output temporarily * Don't need to manually import PDO, don't import OCI8, comment mssql for now * Install sqlite * Enable sqlite3 extension * Add non-PDO PostgreSQL and MySQLi * Set database credentials * Attempt to create the DB tables * Try postgres command line items https://www.appveyor.com/docs/services-databases/ * default is PostgreSQL 9.4 * mysql port for appvoyer is 3306 * Database setup for mysql and postgreSQL * fix directory spelling for mysql * try without single - on each line * try a different table create format * adjust sql install lines * fix yml parsing * try fixing sql import * fix yml parsing again * password needed * remove superfluous semicolon * fix / vs \ * database setup for MSSQL * Is powershell script without `- >` ? * Is the powershell scripting needing single `-` ? * Turn off php -i output, remove switch * try with single - * all powerscript items start with - ps: * completely redo the MSSQL table creation * Don't need composer show output * Try to detect the PHP version and download the needed DLLs * do the DLL downloads before all the other items * try tweaking the dll conditionals * chain IF for && (and) equivalence * try $Env:php_ver_target for condition * Install DLLs after moving to php dir, install non-PDO DLLs, enable them * try if as a powershell item * try $env:PHP * nul is batch syntax. In PowerShell you use $null * try Remove-Item * Specify postgresql94 since appveyor is now postgresql95 by default with postgresql * Fix PHP 7.0 filenames, try /Y switch * ... or not ... * List directory contents, something's not right * Now make sure the extensions are there * try NTS.dll is the not thread safe the correct version to use? * extension type nts * SQLSVR host is (local)\SQL2014 * try adjusting MSSQL db create * try adjusting pgsql db create * dependencies: lowest is broken, just work with current * is MSSQL interfering with other databases? * is the mysql port causing problems? * try sqlcmd -b -E -S * before_build will never run with build: false, need to use before_test this should fix the DB issues * Fix pgSQL * try to force PHP 5.6 to x86 * try to fix parsing error * try fixing yml again * should be valid yml now * Simplify the IF %PHP%==1 conditions for echo block only need to check once If ($env:PHP -eq "1") for the block of echo's * revert condensed if check due to parse error multiple errors of the following type ```bat The output stream for this command is already redirected ``` * remove Get-ChildItem -Path c:\tools\php\ext We no longer need this debug info as we solved the DLL load issue by using the right file version * try setting USE $db in SQLSVR set up * remove commented lines and unnecessary commands * Fix the SQLSVR tests Information based on the references below It seems that PHPUnit deletes the content of the table in question before setting up the table to execute a test. That only works, if the table already exists. Therefore I’ve added a create table jos_dbtest statement with the PDO to fix the issue PHP unit will perform a ‘clean insert’ operation on our database using the the dataset returned by getDataSet. The clean insert operation will truncate or delete_all any tables in the data set (not all tables in the database) and then insert the rows in the dataset. The solution is to create the table before running the test. Additionally we can modify the default functionality by overriding the getSetUpOperation() and getTearDownOperation() methods - https://andreas.heigl.org/2015/08/16/database-testing-with-phpunit-and-sqlite/ - http://stackoverflow.com/questions/10948273/loading-schema-from-sql-file-in-phpunit-test
1 parent fa8e994 commit 2319805

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

.appveyor.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
build: false
2+
shallow_clone: true
3+
platform:
4+
- x64
5+
clone_folder: C:\projects\database
6+
branches:
7+
except:
8+
- gh-pages
9+
## Build matrix for lowest and highest possible targets
10+
environment:
11+
matrix:
12+
- dependencies: current
13+
php_ver_target: 5.6
14+
- dependencies: current
15+
php_ver_target: 7.0
16+
- dependencies: current
17+
php_ver_target: 7.1
18+
19+
## Cache composer bits
20+
cache:
21+
- '%LOCALAPPDATA%\Composer\files -> composer.lock'
22+
init:
23+
- SET PATH=C:\Program Files\OpenSSL;c:\tools\php;%PATH%
24+
- SET COMPOSER_NO_INTERACTION=1
25+
- SET PHP=1
26+
- SET ANSICON=121x90 (121x90)
27+
services:
28+
- mssql2014
29+
- mysql
30+
- postgresql94
31+
- iis
32+
33+
## Install PHP and composer, and run the appropriate composer command
34+
install:
35+
- IF EXIST c:\tools\php (SET PHP=0)
36+
- ps: >-
37+
If ($env:php_ver_target -eq "5.6") {
38+
appveyor-retry cinst --ignore-checksums -y --forcex86 php --version ((choco search php --exact --all-versions -r | select-string -pattern $Env:php_ver_target | Select-Object -first 1) -replace '[php|]','')
39+
} Else {
40+
appveyor-retry cinst --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $Env:php_ver_target | Select-Object -first 1) -replace '[php|]','')}
41+
- cinst -y sqlite
42+
- cd c:\tools\php
43+
- ps: >-
44+
If ($env:php_ver_target -eq "5.6") {
45+
If ($env:PHP -eq "1") {
46+
appveyor DownloadFile https://files.nette.org/misc/php-sqlsrv.zip
47+
7z x php-sqlsrv.zip > $null
48+
copy SQLSRV\php_sqlsrv_56_nts.dll ext\php_sqlsrv_nts.dll
49+
copy SQLSRV\php_pdo_sqlsrv_56_nts.dll ext\php_pdo_sqlsrv_nts.dll
50+
Remove-Item c:\tools\php\* -include .zip}}
51+
- ps: >-
52+
If ($env:php_ver_target -eq "7.0") {
53+
If ($env:PHP -eq "1") {
54+
appveyor DownloadFile https://github.com/Microsoft/msphpsql/releases/download/4.1.5-Windows/7.0.zip
55+
7z x 7.0.zip > $null
56+
copy 7.0\x64\php_pdo_sqlsrv_7_nts.dll ext\php_pdo_sqlsrv_nts.dll
57+
copy 7.0\x64\php_sqlsrv_7_nts.dll ext\php_sqlsrv_nts.dll
58+
Remove-Item c:\tools\php\* -include .zip}}
59+
- ps: >-
60+
If ($env:php_ver_target -eq "7.1") {
61+
If ($env:PHP -eq "1") {
62+
appveyor DownloadFile https://github.com/Microsoft/msphpsql/releases/download/4.1.5-Windows/7.1.zip
63+
7z x 7.1.zip > $null
64+
copy 7.1\x64\php_pdo_sqlsrv_71_nts.dll ext\php_pdo_sqlsrv_nts.dll
65+
copy 7.1\x64\php_sqlsrv_71_nts.dll ext\php_sqlsrv_nts.dll
66+
Remove-Item c:\tools\php\* -include .zip}}
67+
- IF %PHP%==1 copy php.ini-production php.ini /Y
68+
- IF %PHP%==1 echo date.timezone="UTC" >> php.ini
69+
- IF %PHP%==1 echo extension_dir=ext >> php.ini
70+
- IF %PHP%==1 echo extension=php_openssl.dll >> php.ini
71+
- IF %PHP%==1 echo extension=php_mbstring.dll >> php.ini
72+
- IF %PHP%==1 echo extension=php_fileinfo.dll >> php.ini
73+
- IF %PHP%==1 echo extension=php_pdo_mysql.dll >> php.ini
74+
- IF %PHP%==1 echo extension=php_pdo_sqlsrv_nts.dll >> php.ini
75+
- IF %PHP%==1 echo extension=php_sqlsrv_nts.dll >> php.ini
76+
- IF %PHP%==1 echo extension=php_pdo_pgsql.dll >> php.ini
77+
- IF %PHP%==1 echo extension=php_pdo_sqlite.dll >> php.ini
78+
- IF %PHP%==1 echo extension=php_sqlite3.dll >> php.ini
79+
- IF %PHP%==1 echo extension=php_mysqli.dll >> php.ini
80+
- IF %PHP%==1 echo extension=php_pgsql.dll >> php.ini
81+
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
82+
- appveyor-retry appveyor DownloadFile https://getcomposer.org/composer.phar
83+
- cd c:\projects\database
84+
- IF %dependencies%==lowest appveyor-retry composer update --prefer-lowest --no-progress --profile -n
85+
- IF %dependencies%==current appveyor-retry composer install --no-progress --profile
86+
- IF %dependencies%==highest appveyor-retry composer update --no-progress --profile -n
87+
88+
before_test:
89+
# Database setup for mysql via PowerShell tools
90+
- >
91+
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -u root -p"Password12!" -e "CREATE DATABASE IF NOT EXISTS joomla_ut;"
92+
- >
93+
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysql" -u root -p"Password12!" joomla_ut < Tests\Stubs\mysql.sql
94+
# Database setup for postgreSQL
95+
- SET PGUSER=postgres
96+
- SET PGPASSWORD=Password12!
97+
- PATH=C:\Program Files\PostgreSQL\9.4\bin\;%PATH%
98+
- createdb joomla_ut
99+
- psql -d joomla_ut -a -f Tests\Stubs\postgresql.sql
100+
# Database setup for MSSQL
101+
- ps: $sqlInstance = "(local)\SQL2014"
102+
- ps: sqlcmd -b -E -S "$sqlInstance" -Q "CREATE DATABASE joomla_ut"
103+
- ps: sqlcmd -S "$sqlInstance" -U "sa" -P "Password12!" -i $env:APPVEYOR_BUILD_FOLDER\Tests\Stubs\sqlsrv.sql
104+
105+
test_script:
106+
- cd C:\projects\database
107+
- vendor/bin/phpunit -c phpunit.appveyor.xml
108+

Tests/DatabaseSqlsrvCase.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ protected function getConnection()
140140

141141
// Create the PDO object from the DSN and options.
142142
$pdo = new \PDO($dsn, self::$options['user'], self::$options['password']);
143+
$pdo->exec('create table [jos_dbtest]([id] [int] IDENTITY(1,1) NOT NULL, [title] [nvarchar](50) NOT NULL, [start_date] [datetime] NOT NULL, [description] [nvarchar](max) NOT NULL, CONSTRAINT [PK_jos_dbtest_id] PRIMARY KEY CLUSTERED ([id] ASC) WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF))');
143144

144145
return $this->createDefaultDBConnection($pdo, self::$options['database']);
145146
}

phpunit.appveyor.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php" colors="false">
3+
<!-- These constants help setup environment configurations for running optional tests.-->
4+
<php>
5+
<const name="JTEST_DATABASE_MYSQL_DSN" value="host=127.0.0.1;dbname=joomla_ut;user=root;pass=Password12!" />
6+
<const name="JTEST_DATABASE_MYSQLI_DSN" value="host=127.0.0.1;dbname=joomla_ut;user=root;pass=Password12!" />
7+
<const name="JTEST_DATABASE_PGSQL_DSN" value="host=127.0.0.1;port=5432;dbname=joomla_ut;user=postgres;pass=Password12!" />
8+
<const name="JTEST_DATABASE_POSTGRESQL_DSN" value="host=127.0.0.1;port=5432;dbname=joomla_ut;user=postgres;pass=Password12!" />
9+
<!--<const name="JTEST_DATABASE_ORACLE_DSN" value="host=localhost;port=1521;dbname=joomla_ut;user=utuser;pass=ut1234" />-->
10+
<const name="JTEST_DATABASE_SQLSRV_DSN" value="host=(local)\SQL2014;dbname=joomla_ut;user=sa;pass=Password12!" />
11+
</php>
12+
<testsuites>
13+
<testsuite name="Unit">
14+
<directory>Tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
</phpunit>

0 commit comments

Comments
 (0)