Skip to content

Commit ec0ba6f

Browse files
authored
Merge pull request #18 from shivammathur/improve-tests
Add support to run tests after build
2 parents 473a967 + d1ce302 commit ec0ba6f

12 files changed

+368
-24
lines changed

.github/workflows/php.yml

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Build
2828
uses: ./php
2929
with:
30-
php-version: ${{ github.event.inputs.php-version }}
30+
php-version: ${{ inputs.php-version }}
3131
arch: ${{ matrix.arch }}
3232
ts: ${{ matrix.ts }}
3333

@@ -38,14 +38,48 @@ jobs:
3838
artifact-id: ${{ steps.artifacts.outputs.artifact-id }}
3939
steps:
4040
- name: Upload artifacts
41-
uses: actions/upload-artifact/merge@v4
41+
uses: actions/upload-artifact/merge@v5
4242
id: artifacts
4343
with:
4444
name: artifacts
4545
delete-merged: true
46+
tests:
47+
strategy:
48+
matrix:
49+
arch: [x64, x86]
50+
ts: [nts, ts]
51+
opcache: [opcache, nocache]
52+
runs-on: windows-2022
53+
needs: artifacts
54+
steps:
55+
- name: Checkout
56+
uses: actions/checkout@v4
57+
58+
- name: Download artifacts
59+
uses: actions/download-artifact@v5
60+
id: artifacts
61+
with:
62+
name: artifacts
63+
64+
- name: Test PHP
65+
shell: pwsh
66+
continue-on-error: true
67+
run: |
68+
Import-Module (Join-Path $(pwd).Path '\php\BuildPhp') -Force
69+
Invoke-PhpTests -PhpVersion ${{inputs.php-version}} `
70+
-Arch ${{matrix.arch}} `
71+
-Ts ${{matrix.ts}} `
72+
-Opcache ${{matrix.opcache}}
73+
74+
- name: Upload artifacts
75+
uses: actions/upload-artifact@v5
76+
continue-on-error: true
77+
with:
78+
name: test-results-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}
79+
path: test-${{matrix.arch}}-${{matrix.ts}}-${{matrix.opcache}}.xml
4680
upload:
4781
runs-on: ubuntu-latest
48-
needs: artifacts
82+
needs: tests
4983
if: ${{ github.event.inputs.upload == 'true' }}
5084
steps:
5185
- name: Upload to downloads server

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: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,67 @@ function Add-TestRequirements {
3232
[string] $VsVersion,
3333
[Parameter(Mandatory = $false, Position=4, HelpMessage='Tests Directory')]
3434
[ValidateLength(1, [int]::MaxValue)]
35-
[string] $TestsDirectory
35+
[string] $TestsDirectory,
36+
[Parameter(Mandatory = $true, Position=5, HelpMessage='Artifacts Directory')]
37+
[ValidateNotNull()]
38+
[string] $ArtifactsDirectory
3639
)
3740
begin {
3841
}
3942
process {
40-
Get-PhpBuild -PhpVersion $PhpVersion -Arch $Arch -Ts $Ts -VsVersion $VsVersion
41-
Get-PhpTestPack -PhpVersion $PhpVersion -TestsDirectory $TestsDirectory
43+
Add-Type -Assembly "System.IO.Compression.Filesystem"
44+
$versionInUrl = $PhpVersion
45+
if($PhpVersion -eq 'master') {
46+
$versionInUrl = "master"
47+
}
48+
$tsPart = if ($Ts -eq "nts") {"nts-Win32"} else {"Win32"}
49+
$binZipFile = "php-$versionInUrl-$tsPart-$VsVersion-$Arch.zip"
50+
$testZipFile = "php-test-pack-$versionInUrl.zip"
51+
52+
$currentDirectory = (Get-Location).Path
53+
$binZipFilePath = Join-Path $ArtifactsDirectory $binZipFile
54+
$binDirectoryPath = Join-Path $currentDirectory phpbin
55+
56+
$testZipFilePath = Join-Path $ArtifactsDirectory $testZipFile
57+
$testsDirectoryPath = Join-Path $currentDirectory $TestsDirectory
58+
59+
if(-not(Test-Path $binZipFilePath)) {
60+
Write-Host "Downloading PHP build $binZipFile..."
61+
Get-PhpBuild -PhpVersion $PhpVersion -Arch $Arch -Ts $Ts -VsVersion $VsVersion
62+
} else {
63+
[System.IO.Compression.ZipFile]::ExtractToDirectory($binZipFilePath, $binDirectoryPath)
64+
}
65+
66+
if(-not(Test-Path $testZipFilePath)) {
67+
Write-Host "Downloading PHP test pack $testZipFile..."
68+
Get-PhpTestPack -PhpVersion $PhpVersion -TestsDirectory $TestsDirectory
69+
} else {
70+
[System.IO.Compression.ZipFile]::ExtractToDirectory($testZipFilePath, $testsDirectoryPath)
71+
}
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
4296
}
4397
end {
4498
}
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+
}

0 commit comments

Comments
 (0)