Skip to content

Commit 889fbe3

Browse files
committed
Refactor extension specific code out of Invoke-Tests.ps1
1 parent 8df99e7 commit 889fbe3

File tree

7 files changed

+110
-23
lines changed

7 files changed

+110
-23
lines changed

extension/BuildPhpExtension/BuildPhpExtension.psd1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@
100100
'Invoke-Build',
101101
'Invoke-CleanupTempFiles',
102102
'Invoke-Tests',
103+
'Set-AmqpTestEnvironment',
103104
'Set-GAGroup',
105+
'Set-ImagickTestEnvironment',
104106
'Set-NetSecurityProtocolType',
107+
'Set-Oci819TestEnvironment',
108+
'Set-PdoOciTestEnvironment',
109+
'Set-XdebugTestEnvironment',
105110

106111
# Public functions
107112
'Invoke-PhpBuildExtension'

extension/BuildPhpExtension/private/Invoke-Tests.ps1

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,15 @@ Function Invoke-Tests {
1919
$php_dir = Join-Path $currentDirectory php-bin
2020
$env:TEST_PHP_EXECUTABLE = "$php_dir\php.exe"
2121
$env:REPORT_EXIT_STATUS = 1
22-
$env:XDEBUG_MODE = ""
23-
$env:MAGICK_CONFIGURE_PATH = "$currentDirectory\..\deps\bin"
24-
$env:PHP_AMQP_HOST="rabbitmq"
25-
$env:PHP_AMQP_SSL_HOST="rabbitmq.example.org"
26-
if($Config.name -eq 'pdo_oci') {
27-
$env:TEST_WORKERS = 1
28-
Get-PhpSrc -PhpVersion $Config.php_version
2922

30-
# This test is not compatible with Oracle XE
31-
$testPath = "$currentDirectory\php-$($Config.php_version)-src\ext\pdo\tests\gh20553.phpt"
32-
if (Test-Path $testPath) {
33-
Remove-Item $testPath -Force
34-
}
35-
36-
$env:PDO_TEST_DIR = "$currentDirectory\php-$($Config.php_version)-src\ext\pdo\tests"
37-
$env:PDO_OCI_TEST_DIR = "$currentDirectory\tests"
38-
$env:PDO_OCI_TEST_USER = "system"
39-
$env:PDO_OCI_TEST_PASS = "oracle"
40-
$env:PDO_OCI_TEST_DSN = "oci:dbname=localhost:1521/XEPDB1.localdomain;charset=AL32UTF8"
41-
}
42-
if($Config.name -eq 'oci8_19'){
43-
$env:PHP_OCI8_TEST_USER = "system"
44-
$env:PHP_OCI8_TEST_PASS = "oracle"
45-
$env:PHP_OCI8_TEST_DB = "localhost:1521/XEPDB1.localdomain"
23+
# Set up extension-specific test environment
24+
$extensionName = ($Config.name -replace '_(.)', { $_.Groups[1].Value.ToUpper() })
25+
$extensionName = $extensionName.Substring(0,1).ToUpper() + $extensionName.Substring(1)
26+
$cmdletName = "Set-${extensionName}TestEnvironment"
27+
if (Get-Command $cmdletName -ErrorAction SilentlyContinue) {
28+
& $cmdletName -Config $Config
4629
}
30+
4731
$tempOriginal = $env:TEMP
4832
Get-TempFiles
4933
$type='extension'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Function Set-AmqpTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Set up environment variables for AMQP extension tests
5+
.PARAMETER Config
6+
Extension Configuration
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
11+
[PSCustomObject] $Config
12+
)
13+
process {
14+
$env:PHP_AMQP_HOST = "rabbitmq"
15+
$env:PHP_AMQP_SSL_HOST = "rabbitmq.example.org"
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Function Set-ImagickTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Set up environment variables for Imagick extension tests
5+
.PARAMETER Config
6+
Extension Configuration
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
11+
[PSCustomObject] $Config
12+
)
13+
process {
14+
$currentDirectory = (Get-Location).Path
15+
$env:MAGICK_CONFIGURE_PATH = "$currentDirectory\..\deps\bin"
16+
}
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Function Set-Oci819TestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Set up environment variables for oci8_19 extension tests
5+
.PARAMETER Config
6+
Extension Configuration
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
11+
[PSCustomObject] $Config
12+
)
13+
process {
14+
$env:PHP_OCI8_TEST_USER = "system"
15+
$env:PHP_OCI8_TEST_PASS = "oracle"
16+
$env:PHP_OCI8_TEST_DB = "localhost:1521/XEPDB1.localdomain"
17+
}
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Function Set-PdoOciTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Set up environment variables for pdo_oci extension tests
5+
.PARAMETER Config
6+
Extension Configuration
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
11+
[PSCustomObject] $Config
12+
)
13+
process {
14+
$currentDirectory = (Get-Location).Path
15+
$env:TEST_WORKERS = 1
16+
Get-PhpSrc -PhpVersion $Config.php_version
17+
18+
# This test is not compatible with Oracle XE
19+
$testPath = "$currentDirectory\php-$($Config.php_version)-src\ext\pdo\tests\gh20553.phpt"
20+
if (Test-Path $testPath) {
21+
Remove-Item $testPath -Force
22+
}
23+
24+
$env:PDO_TEST_DIR = "$currentDirectory\php-$($Config.php_version)-src\ext\pdo\tests"
25+
$env:PDO_OCI_TEST_DIR = "$currentDirectory\tests"
26+
$env:PDO_OCI_TEST_USER = "system"
27+
$env:PDO_OCI_TEST_PASS = "oracle"
28+
$env:PDO_OCI_TEST_DSN = "oci:dbname=localhost:1521/XEPDB1.localdomain;charset=AL32UTF8"
29+
}
30+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Function Set-XdebugTestEnvironment {
2+
<#
3+
.SYNOPSIS
4+
Set up environment variables for Xdebug extension tests
5+
.PARAMETER Config
6+
Extension Configuration
7+
#>
8+
[OutputType()]
9+
param(
10+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension Configuration')]
11+
[PSCustomObject] $Config
12+
)
13+
process {
14+
$env:XDEBUG_MODE = ""
15+
}
16+
}

0 commit comments

Comments
 (0)