1@echo off
2
3if /i "%GITHUB_ACTIONS%" neq "True" (
4    echo for CI only
5    exit /b 3
6)
7
8set NO_INTERACTION=1
9set REPORT_EXIT_STATUS=1
10set SKIP_IO_CAPTURE_TESTS=1
11
12call %~dp0find-target-branch.bat
13if "%BRANCH%" neq "master" (
14	set STABILITY=stable
15) else (
16	set STABILITY=staging
17)
18set DEPS_DIR=%PHP_BUILD_CACHE_BASE_DIR%\deps-%BRANCH%-%PHP_SDK_VS%-%PHP_SDK_ARCH%
19if not exist "%DEPS_DIR%" (
20	echo "%DEPS_DIR%" doesn't exist
21	exit /b 3
22)
23
24rem setup MySQL related exts
25set MYSQL_PWD=Password12!
26set MYSQL_TEST_PASSWD=%MYSQL_PWD%
27set MYSQL_TEST_USER=root
28set MYSQL_TEST_HOST=127.0.0.1
29set MYSQL_TEST_PORT=3306
30set PDO_MYSQL_TEST_USER=%MYSQL_TEST_USER%
31set PDO_MYSQL_TEST_PASS=%MYSQL_PWD%
32set PDO_MYSQL_TEST_HOST=%MYSQL_TEST_HOST%
33set PDO_MYSQL_TEST_PORT=%MYSQL_TEST_PORT%
34set PDO_MYSQL_TEST_DSN=mysql:host=%PDO_MYSQL_TEST_HOST%;port=%PDO_MYSQL_TEST_PORT%;dbname=test
35mysql --host=%PDO_MYSQL_TEST_HOST% --port=%MYSQL_TEST_PORT% --user=%MYSQL_TEST_USER% --password=%MYSQL_TEST_PASSWD% -e "CREATE DATABASE IF NOT EXISTS test"
36if %errorlevel% neq 0 exit /b 3
37
38rem setup PostgreSQL related exts
39set PGUSER=postgres
40set PGPASSWORD=Password12!
41rem set PGSQL_TEST_CONNSTR=host=127.0.0.1 dbname=test port=5432 user=postgres password=Password12!
42echo ^<?php $conn_str = "host=127.0.0.1 dbname=test port=5432 user=%PGUSER% password=%PGPASSWORD%"; ?^> >> "./ext/pgsql/tests/config.inc"
43set PDO_PGSQL_TEST_DSN=pgsql:host=127.0.0.1 port=5432 dbname=test user=%PGUSER% password=%PGPASSWORD%
44set TMP_POSTGRESQL_BIN=%PGBIN%
45"%TMP_POSTGRESQL_BIN%\createdb.exe" test
46if %errorlevel% neq 0 exit /b 3
47
48rem setup ODBC related exts
49set ODBC_TEST_USER=sa
50set ODBC_TEST_PASS=Password12!
51set ODBC_TEST_DSN=Driver={ODBC Driver 17 for SQL Server};Server=^(local^)\SQLEXPRESS;Database=master;uid=%ODBC_TEST_USER%;pwd=%ODBC_TEST_PASS%
52set PDOTEST_DSN=odbc:%ODBC_TEST_DSN%
53
54rem setup Firebird related exts
55if "%PLATFORM%" == "x64" (
56	set PHP_FIREBIRD_DOWNLOAD_URL=https://github.com/FirebirdSQL/firebird/releases/download/v3.0.9/Firebird-3.0.9.33560-0_x64.zip
57) else (
58	set PHP_FIREBIRD_DOWNLOAD_URL=https://github.com/FirebirdSQL/firebird/releases/download/v3.0.9/Firebird-3.0.9.33560-0_Win32.zip
59)
60curl -sLo Firebird.zip %PHP_FIREBIRD_DOWNLOAD_URL%
617z x -oC:\Firebird Firebird.zip
62set PDO_FIREBIRD_TEST_DATABASE=C:\test.fdb
63set PDO_FIREBIRD_TEST_DSN=firebird:dbname=%PDO_FIREBIRD_TEST_DATABASE%
64set PDO_FIREBIRD_TEST_USER=SYSDBA
65set PDO_FIREBIRD_TEST_PASS=phpfi
66echo create database '%PDO_FIREBIRD_TEST_DATABASE%' user '%PDO_FIREBIRD_TEST_USER%' password '%PDO_FIREBIRD_TEST_PASS%';> C:\Firebird\setup.sql
67C:\Firebird\instsvc.exe install -n TestInstance
68C:\Firebird\isql -q -i C:\Firebird\setup.sql
69C:\Firebird\instsvc.exe start -n TestInstance
70if %errorlevel% neq 0 exit /b 3
71path C:\Firebird;%PATH%
72
73rem prepare for ext/openssl
74rmdir /s /q C:\OpenSSL-Win32 >NUL 2>NUL
75rmdir /s /q C:\OpenSSL-Win64 >NUL 2>NUL
76if "%PLATFORM%" == "x64" (
77	set OPENSSLDIR="C:\Program Files\Common Files\SSL"
78) else (
79	set OPENSSLDIR="C:\Program Files (x86)\Common Files\SSL"
80)
81if /i "%GITHUB_ACTIONS%" equ "True" (
82    rmdir /s /q %OPENSSLDIR% >nul 2>&1
83)
84mkdir %OPENSSLDIR%
85if %errorlevel% neq 0 exit /b 3
86copy %DEPS_DIR%\template\ssl\openssl.cnf %OPENSSLDIR%
87if %errorlevel% neq 0 exit /b 3
88rem set OPENSSL_CONF=%OPENSSLDIR%\openssl.cnf
89set OPENSSL_CONF=
90rem set SSLEAY_CONF=
91
92rem prepare for OPcache
93if "%OPCACHE%" equ "1" set OPCACHE_OPTS=-d opcache.enable=1 -d opcache.enable_cli=1 -d opcache.protect_memory=1 -d opcache.jit_buffer_size=16M
94rem work-around for failing to dl(mysqli) with OPcache (https://github.com/php/php-src/issues/8508)
95if "%OPCACHE%" equ "1" set OPCACHE_OPTS=%OPCACHE_OPTS% -d extension=mysqli
96
97rem prepare for enchant
98mkdir %~d0\usr\local\lib\enchant-2
99if %errorlevel% neq 0 exit /b 3
100copy %DEPS_DIR%\bin\libenchant2_hunspell.dll %~d0\usr\local\lib\enchant-2
101if %errorlevel% neq 0 exit /b 3
102mkdir %~d0\usr\local\share\enchant\hunspell
103if %errorlevel% neq 0 exit /b 3
104echo Fetching enchant dicts
105pushd %~d0\usr\local\share\enchant\hunspell
106powershell -Command wget https://downloads.php.net/~windows/qa/appveyor/ext/enchant/dict.zip -OutFile dict.zip
107unzip dict.zip
108del /q dict.zip
109popd
110
111rem prepare for snmp
112set MIBDIRS=%DEPS_DIR%\share\mibs
113start %DEPS_DIR%\bin\snmpd.exe -C -c %GITHUB_WORKSPACE%\ext\snmp\tests\snmpd.conf -Ln
114
115set PHP_BUILD_DIR=%PHP_BUILD_OBJ_DIR%\Release
116if "%THREAD_SAFE%" equ "1" set PHP_BUILD_DIR=%PHP_BUILD_DIR%_TS
117
118rem prepare for mail
119curl -sLo hMailServer.exe https://www.hmailserver.com/download_file/?downloadid=271
120hMailServer.exe /verysilent
121cd %APPVEYOR_BUILD_FOLDER%
122%PHP_BUILD_DIR%\php.exe -dextension_dir=%PHP_BUILD_DIR% -dextension=com_dotnet appveyor\setup_hmailserver.php
123
124mkdir %PHP_BUILD_DIR%\test_file_cache
125rem generate php.ini
126echo extension_dir=%PHP_BUILD_DIR% > %PHP_BUILD_DIR%\php.ini
127echo opcache.file_cache=%PHP_BUILD_DIR%\test_file_cache >> %PHP_BUILD_DIR%\php.ini
128if "%OPCACHE%" equ "1" echo zend_extension=php_opcache.dll >> %PHP_BUILD_DIR%\php.ini
129rem work-around for some spawned PHP processes requiring OpenSSL
130echo extension=php_openssl.dll >> %PHP_BUILD_DIR%\php.ini
131
132rem remove ext dlls for which tests are not supported
133for %%i in (ldap oci8_12c pdo_oci) do (
134	del %PHP_BUILD_DIR%\php_%%i.dll
135)
136
137set TEST_PHPDBG_EXECUTABLE=%PHP_BUILD_DIR%\phpdbg.exe
138
139mkdir c:\tests_tmp
140
141nmake test TESTS="%OPCACHE_OPTS% -g FAIL,BORK,LEAK,XLEAK --no-progress -q --offline --show-diff --show-slow 1000 --set-timeout 120 --temp-source c:\tests_tmp --temp-target c:\tests_tmp --bless %PARALLEL%"
142
143set EXIT_CODE=%errorlevel%
144
145taskkill /f /im snmpd.exe
146
147if %EXIT_CODE% GEQ 1 (
148	git checkout ext\pgsql\tests\config.inc
149	git diff > bless_tests.patch
150)
151
152exit /b %EXIT_CODE%
153