Skip to content

Commit d1ce302

Browse files
committed
Improve test requirements
1 parent 2761b7f commit d1ce302

11 files changed

+280
-20
lines changed

.github/workflows/php.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ jobs:
6161
with:
6262
name: artifacts
6363

64-
- name: Setup MySQL
65-
uses: ankane/setup-mysql@v1
66-
with:
67-
database: test
68-
6964
- name: Test PHP
7065
shell: pwsh
7166
continue-on-error: true

php/BuildPhp/BuildPhp.psd1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@
6161

6262
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
6363
FunctionsToExport = @(
64-
# Private functions
64+
# Private functions (sorted)
6565
'Add-BuildRequirements',
66-
'Add-TestRequirements',
6766
'Add-Path',
67+
'Add-TestRequirements',
6868
'Add-Vs',
6969
'Get-File',
7070
'Get-OciSdk',
@@ -74,11 +74,18 @@
7474
'Get-PhpTestPack',
7575
'Get-SourcePhpVersion',
7676
'Get-TestSettings',
77-
'Get-TestsList'
78-
'Get-VsVersionHelper',
77+
'Get-TestsList',
7978
'Get-VsVersion',
79+
'Get-VsVersionHelper',
80+
'Set-EnchantTestEnvironment',
81+
'Set-FirebirdTestEnvironment',
82+
'Set-MsSqlTestEnvironment',
83+
'Set-MySqlTestEnvironment',
8084
'Set-NetSecurityProtocolType',
81-
'Set-PhpIniForTests'
85+
'Set-OdbcTestEnvironment',
86+
'Set-PgSqlTestEnvironment',
87+
'Set-PhpIniForTests',
88+
'Set-SnmpTestEnvironment',
8289

8390
# Public functions
8491
'Invoke-PhpBuild',
@@ -139,4 +146,3 @@
139146
# DefaultCommandPrefix = ''
140147

141148
}
142-

php/BuildPhp/private/Add-TestRequirements.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ function Add-TestRequirements {
6969
} else {
7070
[System.IO.Compression.ZipFile]::ExtractToDirectory($testZipFilePath, $testsDirectoryPath)
7171
}
72+
73+
$ldapDll = Join-Path $binDirectoryPath 'php_ldap.dll'
74+
Remove-Item -LiteralPath $ldapDll -Force -ErrorAction SilentlyContinue
75+
76+
$phpExePath = Join-Path $binDirectoryPath 'php.exe'
77+
$phpCgiPath = Join-Path $binDirectoryPath 'php-cgi.exe'
78+
try { & editbin "/stack:8388608" $phpExePath | Out-Null } catch {}
79+
try { & editbin "/stack:8388608" $phpCgiPath | Out-Null } catch {}
80+
81+
$Env:TEST_PHPDBG_EXECUTABLE = (Join-Path $binDirectoryPath 'phpdbg.exe')
82+
83+
Get-PhpSdk
84+
$env:DEPS_DIR = "$currentDirectory/../deps"
85+
New-Item "$env:DEPS_DIR" -ItemType "directory" -Force > $null 2>&1
86+
$branch = if ($PhpVersion -eq 'master') {'master'} else {($PhpVersion -split '\.')[0..1] -join '.'}
87+
& "$currentDirectory\php-sdk\bin\phpsdk_deps.bat" --update --no-backup --branch $branch --stability staging --deps $env:DEPS_DIR --crt $VsVersion --arch $Arch
88+
89+
Set-MySqlTestEnvironment
90+
Set-PgSqlTestEnvironment
91+
Set-OdbcTestEnvironment
92+
Set-MsSqlTestEnvironment
93+
Set-FirebirdTestEnvironment
94+
Set-EnchantTestEnvironment
95+
Set-SnmpTestEnvironment -TestsDirectoryPath $testsDirectoryPath
7296
}
7397
end {
7498
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function Set-EnchantTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Prepare Enchant (hunspell) runtime and dictionaries for tests.
5+
#>
6+
[CmdletBinding()]
7+
param ()
8+
process {
9+
$driveRoot = [System.IO.Path]::GetPathRoot((Get-Location).Path)
10+
$libDir = Join-Path $driveRoot 'usr\local\lib\enchant-2'
11+
$dictDir = Join-Path $driveRoot 'usr\local\share\enchant\hunspell'
12+
13+
New-Item -ItemType Directory -Force -Path $libDir | Out-Null
14+
New-Item -ItemType Directory -Force -Path $dictDir | Out-Null
15+
16+
$depsDir = $env:DEPS_DIR
17+
if (-not $depsDir) { throw 'DEPS_DIR is not set.' }
18+
$srcDll = Join-Path $depsDir 'bin\libenchant2_hunspell.dll'
19+
if (-not (Test-Path -LiteralPath $srcDll)) {
20+
throw "libenchant2_hunspell.dll not found at $srcDll"
21+
}
22+
Copy-Item -LiteralPath $srcDll -Destination $libDir -Force
23+
24+
Write-Host 'Fetching enchant dicts'
25+
Push-Location $dictDir
26+
try {
27+
$zip = Join-Path $dictDir 'dict.zip'
28+
$url = 'https://downloads.php.net/~windows/qa/appveyor/ext/enchant/dict.zip'
29+
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile $zip
30+
try {
31+
Expand-Archive -LiteralPath $zip -DestinationPath $dictDir -Force
32+
} catch {
33+
Add-Type -AssemblyName System.IO.Compression.FileSystem
34+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zip, $dictDir)
35+
}
36+
Remove-Item -LiteralPath $zip -Force -ErrorAction SilentlyContinue
37+
} finally {
38+
Pop-Location
39+
}
40+
}
41+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
function Set-FirebirdTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure Firebird for PDO_Firebird tests on Windows.
5+
#>
6+
[CmdletBinding()]
7+
param ()
8+
process {
9+
$destDir = 'C:\Firebird'
10+
$firebirdVersion = 'v4.0.4'
11+
$firebirdRelease = "https://github.com/FirebirdSQL/firebird/releases/download/$firebirdVersion"
12+
New-Item -ItemType Directory -Force -Path $destDir | Out-Null
13+
14+
$is64 = [Environment]::Is64BitOperatingSystem
15+
$url = if ($is64) {
16+
"$firebirdRelease/Firebird-4.0.4.3010-0-x64.zip"
17+
} else {
18+
"$firebirdRelease/Firebird-4.0.4.3010-0-Win32.zip"
19+
}
20+
21+
$zipPath = Join-Path $destDir 'Firebird.zip'
22+
Invoke-WebRequest -Uri $url -UseBasicParsing -OutFile $zipPath
23+
24+
try {
25+
Expand-Archive -LiteralPath $zipPath -DestinationPath $destDir -Force
26+
} catch {
27+
Add-Type -AssemblyName System.IO.Compression.FileSystem
28+
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath, $destDir)
29+
}
30+
31+
$env:PDO_FIREBIRD_TEST_DATABASE = 'C:\test.fdb'
32+
$env:PDO_FIREBIRD_TEST_DSN = "firebird:dbname=127.0.0.1:$($env:PDO_FIREBIRD_TEST_DATABASE)"
33+
$env:PDO_FIREBIRD_TEST_USER = 'SYSDBA'
34+
$env:PDO_FIREBIRD_TEST_PASS = 'phpfi'
35+
36+
$createUserSql = Join-Path $destDir 'create_user.sql'
37+
Set-Content -Path $createUserSql -Value "create user $($env:PDO_FIREBIRD_TEST_USER) password '$($env:PDO_FIREBIRD_TEST_PASS)';" -Encoding ASCII
38+
Add-Content -Path $createUserSql -Value 'commit;' -Encoding ASCII
39+
40+
$setupSql = Join-Path $destDir 'setup.sql'
41+
Set-Content -Path $setupSql -Value "create database '$($env:PDO_FIREBIRD_TEST_DATABASE)' user '$($env:PDO_FIREBIRD_TEST_USER)' password '$($env:PDO_FIREBIRD_TEST_PASS)';" -Encoding ASCII
42+
43+
& (Join-Path $destDir 'instsvc.exe') install -n TestInstance | Out-Null
44+
& (Join-Path $destDir 'isql') -q -i $setupSql | Out-Null
45+
& (Join-Path $destDir 'isql') -q -i $createUserSql -user sysdba $env:PDO_FIREBIRD_TEST_DATABASE | Out-Null
46+
& (Join-Path $destDir 'instsvc.exe') start -n TestInstance | Out-Null
47+
48+
Add-Path $destDir
49+
}
50+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function Set-MsSqlTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Install Microsoft SQL Server Express required for SQL Server-related tests.
5+
#>
6+
[CmdletBinding()]
7+
param ()
8+
process {
9+
& choco install sql-server-express -y --no-progress --install-arguments="/SECURITYMODE=SQL /SAPWD=Password12!" | Out-Null
10+
}
11+
}
12+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
function Set-MySqlTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure environment variables for MySQL-related PHP tests and ensure the test database exists.
5+
#>
6+
[CmdletBinding()]
7+
param (
8+
)
9+
process {
10+
$Database = 'test'
11+
$DbHost = '127.0.0.1'
12+
$User = 'root'
13+
$Password = 'Password12!'
14+
$Port = 3306
15+
& mysqld --initialize-insecure | Out-Null
16+
& mysqld --install | Out-Null
17+
& net start "MySQL" | Out-Null
18+
& mysql --port=$Port --user=root --password="" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$($Password)'; FLUSH PRIVILEGES;" | Out-Null
19+
20+
$env:MYSQL_PWD = $Password
21+
$env:MYSQL_TEST_PASSWD = $env:MYSQL_PWD
22+
$env:MYSQL_TEST_USER = $User
23+
$env:MYSQL_TEST_HOST = $DbHost
24+
$env:MYSQL_TEST_PORT = "$Port"
25+
$env:MYSQL_TEST_DB = $Database
26+
27+
$env:PDO_MYSQL_TEST_USER = $env:MYSQL_TEST_USER
28+
$env:PDO_MYSQL_TEST_PASS = $env:MYSQL_PWD
29+
$env:PDO_MYSQL_TEST_HOST = $env:MYSQL_TEST_HOST
30+
$env:PDO_MYSQL_TEST_PORT = $env:MYSQL_TEST_PORT
31+
$env:PDO_MYSQL_TEST_DSN = "mysql:host=$($env:PDO_MYSQL_TEST_HOST);port=$($env:PDO_MYSQL_TEST_PORT);dbname=$Database"
32+
33+
$params = @(
34+
"--host=$($env:PDO_MYSQL_TEST_HOST)",
35+
"--port=$($env:MYSQL_TEST_PORT)",
36+
"--user=$($env:MYSQL_TEST_USER)",
37+
"--password=$($env:MYSQL_TEST_PASSWD)",
38+
"-e", "CREATE DATABASE IF NOT EXISTS $Database"
39+
)
40+
41+
& mysql @params | Out-Null
42+
}
43+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function Set-OdbcTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure environment variables for ODBC/PDO ODBC SQL Server tests.
5+
#>
6+
[CmdletBinding()]
7+
param ()
8+
process {
9+
$env:ODBC_TEST_USER = 'sa'
10+
$env:ODBC_TEST_PASS = 'Password12!'
11+
$env:ODBC_TEST_DSN = "Driver={ODBC Driver 17 for SQL Server};Server=(local)\SQLEXPRESS;Database=master;uid=$($env:ODBC_TEST_USER);pwd=$($env:ODBC_TEST_PASS)"
12+
$env:PDOTEST_DSN = "odbc:$($env:ODBC_TEST_DSN)"
13+
}
14+
}
15+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Set-PgSqlTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure environment variables for PostgreSQL-related PHP tests and ensure the test database exists.
5+
#>
6+
[CmdletBinding()]
7+
param ()
8+
process {
9+
$env:PGUSER = 'postgres'
10+
$env:PGPASSWORD = 'Password12!'
11+
Set-Service -Name "postgresql-x64-14" -StartupType manual -Status Running
12+
$prevPgPwd = $env:PGPASSWORD
13+
$env:PGPASSWORD = 'root'
14+
& "$env:PGBIN\psql" -U postgres -c "ALTER USER ${$env.PGUSER} WITH PASSWORD '$($prevPgPwd)';" | Out-Null
15+
$env:PGPASSWORD = $prevPgPwd
16+
$env:PDO_PGSQL_TEST_DSN = "pgsql:host=127.0.0.1 port=5432 dbname=test user=$($env:PGUSER) password=$($env:PGPASSWORD)"
17+
if ($env:PGBIN) {
18+
$env:TMP_POSTGRESQL_BIN = $env:PGBIN
19+
}
20+
21+
$testsRoot = Join-Path (Get-Location).Path 'tests'
22+
$configDir = Join-Path $testsRoot 'ext/pgsql/tests'
23+
$configFile = Join-Path $configDir 'config.inc'
24+
New-Item -ItemType Directory -Force -Path $configDir | Out-Null
25+
26+
$phpLine = "<?php $`conn_str = 'host=127.0.0.1 dbname=test port=5432 user=$($env:PGUSER) password=$($env:PGPASSWORD)'; ?>"
27+
Add-Content -Path $configFile -Value $phpLine -Encoding ASCII
28+
29+
$createdb = Join-Path $env:TMP_POSTGRESQL_BIN 'createdb.exe'
30+
if (-not (Test-Path $createdb)) {
31+
throw "createdb.exe not found. Ensure PGBIN is set to PostgreSQL bin directory."
32+
}
33+
34+
& $createdb 'test' | Out-Null
35+
}
36+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
function Set-SnmpTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Configure SNMP test environment: set MIBDIRS, patch snmpd.conf, and start snmpd.
5+
.PARAMETER TestsDirectoryPath
6+
Absolute path to the extracted PHP tests directory (use the $testsDirectoryPath from Add-TestRequirements).
7+
#>
8+
[CmdletBinding()]
9+
param (
10+
[Parameter(Mandatory = $true)]
11+
[ValidateNotNullOrEmpty()]
12+
[string] $TestsDirectoryPath
13+
)
14+
process {
15+
if (-not $env:DEPS_DIR) {
16+
throw 'DEPS_DIR is not set. Ensure dependencies are downloaded before SNMP setup.'
17+
}
18+
19+
$env:MIBDIRS = Join-Path $env:DEPS_DIR 'share\mibs'
20+
21+
$confPath = Join-Path $TestsDirectoryPath 'ext\snmp\tests\snmpd.conf'
22+
if (-not (Test-Path -LiteralPath $confPath)) {
23+
throw "snmpd.conf not found at $confPath"
24+
}
25+
26+
$forwardTestsRoot = ($TestsDirectoryPath -replace '\\','/')
27+
$bigTestJs = "$forwardTestsRoot/ext/snmp/tests/bigtest.js"
28+
29+
$content = Get-Content -LiteralPath $confPath -Raw -Encoding UTF8
30+
$newLine = "exec HexTest cscript.exe /nologo $bigTestJs"
31+
$updated = [System.Text.RegularExpressions.Regex]::Replace(
32+
$content,
33+
'^exec\s+HexTest\s+.*$',
34+
[System.Text.RegularExpressions.Regex]::Escape($newLine).Replace('\/','/'),
35+
[System.Text.RegularExpressions.RegexOptions]::Multiline
36+
)
37+
if ($updated -ne $content) {
38+
Set-Content -LiteralPath $confPath -Value $updated -Encoding UTF8
39+
}
40+
41+
$snmpd = Join-Path $env:DEPS_DIR 'bin\snmpd.exe'
42+
if (-not (Test-Path -LiteralPath $snmpd)) {
43+
throw "snmpd.exe not found at $snmpd"
44+
}
45+
Start-Process -FilePath $snmpd -ArgumentList @('-C','-c', $confPath, '-Ln') -WindowStyle Hidden | Out-Null
46+
}
47+
}

0 commit comments

Comments
 (0)