@@ -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 }
0 commit comments