Skip to content

Commit f2e00af

Browse files
committed
Fix PHP source checkout and test setup
1 parent f302d95 commit f2e00af

6 files changed

Lines changed: 78 additions & 21 deletions

File tree

.github/workflows/local-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v6
1919

20+
- name: Configure PHP source line endings
21+
shell: pwsh
22+
run: |
23+
git config --global core.autocrlf false
24+
git config --global core.eol lf
25+
2026
- name: Resolve latest PHP 8.5 and Xdebug releases
2127
id: versions
2228
shell: pwsh

.github/workflows/test-php-libs-from-source.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ jobs:
2121
ts: [nts, ts]
2222
runs-on: windows-2022
2323
steps:
24+
- name: Configure PHP source line endings
25+
shell: pwsh
26+
run: |
27+
git config --global core.autocrlf false
28+
git config --global core.eol lf
29+
2430
- name: Checkout PHP source
2531
uses: actions/checkout@v6
2632
with:

php/BuildPhp/private/Set-MsSqlTestEnvironment.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,29 @@ function Set-MsSqlTestEnvironment {
66
[CmdletBinding()]
77
param ()
88
process {
9+
if(Test-Path mssql_init) {
10+
return
11+
}
12+
13+
$serviceName = 'MSSQL$SQLEXPRESS'
914
& choco install sql-server-express -y --no-progress --install-arguments="/SECURITYMODE=SQL /SAPWD=Password12!"
15+
if (@(0, 3010) -notcontains $LASTEXITCODE) {
16+
throw "Failed to install SQL Server Express. choco exited with $LASTEXITCODE."
17+
}
18+
19+
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
20+
21+
if (-not $service) {
22+
throw "SQL Server Express service $serviceName was not found."
23+
}
24+
25+
Set-Service -Name $serviceName -StartupType Manual
26+
if ($service.Status -ne 'Running') {
27+
Start-Service -Name $serviceName
28+
$service = Get-Service -Name $serviceName
29+
}
30+
$service.WaitForStatus('Running', [TimeSpan]::FromSeconds(120))
31+
Set-Content -Path mssql_init -Value "initialized" -Encoding ASCII
1032
}
1133
}
1234

php/BuildPhp/private/Set-OdbcTestEnvironment.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ function Set-OdbcTestEnvironment {
66
[CmdletBinding()]
77
param ()
88
process {
9+
Set-MsSqlTestEnvironment
10+
911
$env:ODBC_TEST_USER = 'sa'
1012
$env:ODBC_TEST_PASS = 'Password12!'
1113
$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)"
14+
$env:PDOTEST_DSN = "odbc:$($env:ODBC_TEST_DSN)"
15+
$env:PDOTEST_USER = $env:ODBC_TEST_USER
16+
$env:PDOTEST_PASS = $env:ODBC_TEST_PASS
17+
$env:PDO_ODBC_TEST_DSN = $env:PDOTEST_DSN
18+
$env:PDO_ODBC_TEST_USER = $env:ODBC_TEST_USER
19+
$env:PDO_ODBC_TEST_PASS = $env:ODBC_TEST_PASS
1320
}
1421
}
1522

php/BuildPhp/private/Set-PgSqlTestEnvironment.ps1

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,52 @@ function Set-PgSqlTestEnvironment {
66
[CmdletBinding()]
77
param ()
88
process {
9+
$database = 'test'
10+
$hostName = '127.0.0.1'
11+
$port = 5432
912
$env:PGUSER = 'postgres'
1013
$env:PGPASSWORD = 'Password12!'
14+
1115
if(-not(Test-Path pgsql_init)) {
12-
Set-Service -Name "postgresql-x64-14" -StartupType manual -Status Running -WarningAction SilentlyContinue
16+
Set-Service -Name "postgresql-x64-14" -StartupType manual -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
17+
Start-Service -Name "postgresql-x64-14" -WarningAction SilentlyContinue -ErrorAction SilentlyContinue
18+
$service = Get-Service -Name "postgresql-x64-14" -ErrorAction SilentlyContinue
19+
if ($service) {
20+
$service.WaitForStatus('Running', [TimeSpan]::FromSeconds(60))
21+
}
1322
Set-Content -Path pgsql_init -Value "initialized" -Encoding ASCII
1423
}
15-
$prevPgPwd = $env:PGPASSWORD
16-
$env:PGPASSWORD = 'root'
17-
if(-not(Test-Path pgsql_db_created)) {
18-
& "$env:PGBIN\psql" -U postgres -c "ALTER USER $($env:PGUSER) WITH PASSWORD '$($prevPgPwd)';"
19-
Set-Content -Path pgsql_db_created -Value "db_created" -Encoding ASCII
20-
}
21-
$env:PGPASSWORD = $prevPgPwd
22-
$env:PDO_PGSQL_TEST_DSN = "pgsql:host=127.0.0.1 port=5432 dbname=test user=$($env:PGUSER) password=$($env:PGPASSWORD)"
24+
2325
if ($env:PGBIN) {
2426
$env:TMP_POSTGRESQL_BIN = $env:PGBIN
2527
}
2628

27-
$testsRoot = Join-Path (Get-Location).Path 'tests'
28-
$configDir = Join-Path $testsRoot 'ext/pgsql/tests'
29-
$configFile = Join-Path $configDir 'config.inc'
30-
New-Item -ItemType Directory -Force -Path $configDir
31-
32-
$phpLine = "<?php $`conn_str = 'host=127.0.0.1 dbname=test port=5432 user=$($env:PGUSER) password=$($env:PGPASSWORD)'; ?>"
33-
Add-Content -Path $configFile -Value $phpLine -Encoding ASCII
34-
29+
$psql = Join-Path $env:TMP_POSTGRESQL_BIN 'psql.exe'
3530
$createdb = Join-Path $env:TMP_POSTGRESQL_BIN 'createdb.exe'
31+
if (-not (Test-Path $psql)) {
32+
throw "psql.exe not found. Ensure PGBIN is set to PostgreSQL bin directory."
33+
}
3634
if (-not (Test-Path $createdb)) {
3735
throw "createdb.exe not found. Ensure PGBIN is set to PostgreSQL bin directory."
3836
}
37+
38+
$connStr = "host=$hostName dbname=$database port=$port user=$($env:PGUSER) password=$($env:PGPASSWORD)"
39+
$env:PGSQL_TEST_CONNSTR = $connStr
40+
$env:PDO_PGSQL_TEST_DSN = "pgsql:host=$hostName port=$port dbname=$database user=$($env:PGUSER) password=$($env:PGPASSWORD)"
41+
42+
if(-not(Test-Path pgsql_password_set)) {
43+
$prevPgPwd = $env:PGPASSWORD
44+
try {
45+
$env:PGPASSWORD = 'root'
46+
& $psql -U postgres -c "ALTER USER $($env:PGUSER) WITH PASSWORD '$prevPgPwd';"
47+
} finally {
48+
$env:PGPASSWORD = $prevPgPwd
49+
}
50+
Set-Content -Path pgsql_password_set -Value "password_set" -Encoding ASCII
51+
}
52+
3953
if(-not(Test-Path pgsql_test_db_created)) {
40-
& $createdb 'test'
54+
& $createdb $database
4155
Set-Content -Path pgsql_test_db_created -Value "test_db_created" -Encoding ASCII
4256
}
4357
}

php/BuildPhp/private/Set-SnmpTestEnvironment.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ function Set-SnmpTestEnvironment {
3131
$updated = [System.Text.RegularExpressions.Regex]::Replace(
3232
$content,
3333
'^exec\s+HexTest\s+.*$',
34-
[System.Text.RegularExpressions.Regex]::Escape($newLine).Replace('\/','/'),
34+
[System.Text.RegularExpressions.MatchEvaluator] { param($match) $newLine },
3535
[System.Text.RegularExpressions.RegexOptions]::Multiline
3636
)
3737
if ($updated -ne $content) {
38-
Set-Content -LiteralPath $confPath -Value $updated -Encoding UTF8
38+
$utf8NoBom = [System.Text.UTF8Encoding]::new($false)
39+
[System.IO.File]::WriteAllText($confPath, $updated, $utf8NoBom)
3940
}
4041

4142
$snmpd = Join-Path $env:DEPS_DIR 'bin\snmpd.exe'
@@ -50,6 +51,7 @@ function Set-SnmpTestEnvironment {
5051
if(-not(Test-Path snmpd_running)) {
5152
Start-Process -FilePath $snmpd -ArgumentList @('-C','-c', $confPath, '-Ln') -WindowStyle Hidden
5253
Set-Content -Path snmpd_running -Value "running" -Encoding ASCII
54+
Start-Sleep -Seconds 2
5355
}
5456
}
5557
}

0 commit comments

Comments
 (0)