-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathInstall-Enable-Extensions.Tests.ps1
More file actions
161 lines (160 loc) · 10.1 KB
/
Install-Enable-Extensions.Tests.ps1
File metadata and controls
161 lines (160 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Describe 'Install-Enable-Extensions' {
Mock -ModuleName PhpManager Get-PhpDownloadCache { return Join-Path -Path $Global:PHPMANAGER_TESTPATH -ChildPath download-cache }
$testCases = @(
@{version = '7.1'; path = (Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid)}
)
<# I don't know how to setup the VCRedist 2017 on nanoserver: let's skip PHP 7.2 on it #>
if (Join-Path -Path $Env:windir -ChildPath System32\imm32.dll | Test-Path -PathType Leaf) {
$testCases += @{version = '7.2'; path = (Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid)}
$testCases += @{version = '8.3'; path = (Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid)}
}
foreach ($testCase in $testCases) {
if (Test-Path -LiteralPath $testCase.path) {
Remove-Item -LiteralPath $testCase.path -Recurse -Force
}
}
try {
foreach ($testCase in $testCases) {
Install-Php -Version $testCase.version -Architecture x64 -ThreadSafe $true -Path $testCase.path
}
It -Name 'should enable/disable GD and mbstring on PHP <version>' -TestCases $testCases {
param ($path)
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'mbstring' -or $_.Handle -eq 'gd'} | Should -HaveCount 2
Disable-PhpExtension -Extension mbstring,gd -Path $path
Enable-PhpExtension -Extension mbstring,gd -Path $path
Get-PhpExtension -Path $path | Where-Object {$_.State -eq 'Enabled' -and $_.Type -eq 'Php' } | Where-Object { $_.Handle -eq 'mbstring' -or $_.Handle -eq 'gd'} | Should -HaveCount 2
Disable-PhpExtension -Extension mbstring,gd -Path $path
Get-PhpExtension -Path $path | Where-Object {$_.State -eq 'Enabled' } | Where-Object { $_.Handle -eq 'mbstring' -or $_.Handle -eq 'gd'} | Should -HaveCount 0
}
It -Name 'should download and install xdebug on PHP <version>' -TestCases $testCases {
param ($path)
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'xdebug' } | Should -HaveCount 0
Install-PhpExtension -Extension xdebug -Path $path
$xdebug = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'xdebug' }
$xdebug | Should -HaveCount 1
$xdebug.Type | Should -BeExactly 'Zend'
$xdebug.State | Should -BeExactly 'Enabled'
Disable-PhpExtension -Extension xdebug -Path $path
$xdebug = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'xdebug' }
$xdebug | Should -HaveCount 1
$xdebug.Type | Should -BeExactly 'Zend'
$xdebug.State | Should -BeExactly 'Disabled'
}
It -Name 'should download and install imagick on PHP <version>' -TestCases $testCases {
param ($path, $version)
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'imagick' } | Should -HaveCount 0
if ($version -eq '7.2') {
Install-PhpExtension -Extension imagick -Path $path -MinimumStability snapshot
} else {
Install-PhpExtension -Extension imagick -Path $path
}
$imagick = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'imagick' }
$imagick | Should -HaveCount 1
$imagick.Type | Should -BeExactly 'Php'
$imagick.State | Should -BeExactly 'Enabled'
Disable-PhpExtension -Extension imagick -Path $path
$imagick = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'imagick' }
$imagick | Should -HaveCount 1
$imagick.Type | Should -BeExactly 'Php'
$imagick.State | Should -BeExactly 'Disabled'
}
It -Name 'should download and install msgpack-beta on PHP <version>' -TestCases $testCases {
param ($path, $version)
if ($version -ne '7.2') {
Set-ItResult -Skipped -Because "Not supported on PHP $version"
}
$msgpack = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'msgpack' }
$msgpack | Should -HaveCount 0
Install-PhpExtension -Extension msgpack -Path $path -MinimumStability beta -MaximumStability beta
$msgpack = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'msgpack' }
$msgpack | Should -HaveCount 1
}
It -Name 'should download and install pdo_sqlsrv-5.9.0-preview on PHP <version>' -TestCases $testCases {
param ($path, $version)
if ($version -ne '7.2') {
Set-ItResult -Skipped -Because "Not supported on PHP $version"
}
if (-not(Get-ChildItem -Path "$($Env:WinDir)\System32" -Filter msodbcsql*.dll)) {
Set-ItResult -Skipped -Because "Missing required system libraries"
}
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'pdo_sqlsrv' } | Should -HaveCount 0
Install-PhpExtension -Extension pdo_sqlsrv -Version 5.9.0 -MinimumStability devel -MaximumStability devel -Path $path
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'pdo_sqlsrv' } | Should -HaveCount 1
}
It -Name 'should download and install sqlsrv-5.9.0-preview on PHP <version>' -TestCases $testCases {
param ($path, $version)
if ($version -ne '7.2') {
Set-ItResult -Skipped -Because "Not supported on PHP $version"
}
if (-not(Get-ChildItem -Path "$($Env:WinDir)\System32" -Filter msodbcsql*.dll)) {
Set-ItResult -Skipped -Because "Missing required system libraries"
}
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'sqlsrv' } | Should -HaveCount 0
Install-PhpExtension -Extension sqlsrv -Version 5.9.0 -MinimumStability devel -MaximumStability devel -Path $path
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'sqlsrv' } | Should -HaveCount 1
}
It -Name 'should download and install yaml on PHP <version>' -TestCases $testCases {
param ($path, $version)
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'yaml' } | Should -HaveCount 0
Install-PhpExtension -Extension yaml -Path $path
$yaml = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'yaml' }
$yaml | Should -HaveCount 1
$yaml.Type | Should -BeExactly 'Php'
$yaml.State | Should -BeExactly 'Enabled'
}
It -Name 'should download and install couchbase on PHP <version>' -TestCases $testCases {
param ($path, $version)
if (-not(Join-Path -Path $Env:windir -ChildPath System32\msvcp140.dll | Test-Path -PathType Leaf)) {
if (-not(Join-Path -Path $Env:windir -ChildPath System32\msvcp160.dll | Test-Path -PathType Leaf)) {
Set-ItResult -Skipped -Because 'Missing some required system DLLs'
}
}
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'couchbase' } | Should -HaveCount 0
Install-PhpExtension -Extension couchbase -Path $path
$couchbase = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'couchbase' }
$couchbase | Should -HaveCount 1
$couchbase.Type | Should -BeExactly 'Php'
$couchbase.State | Should -BeExactly 'Enabled'
}
It -Name 'should download and install decimal on PHP <version>' -TestCases $testCases {
param ($path, $version)
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'decimal' } | Should -HaveCount 0
Install-PhpExtension -Extension decimal -Path $path
$decimal = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'decimal' }
$decimal | Should -HaveCount 1
$decimal.Type | Should -BeExactly 'Php'
$decimal.State | Should -BeExactly 'Enabled'
}
It -Name 'should handle multiple extension versions' {
$phpPath = Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid
Install-Php -Version 7.1 -Architecture x64 -ThreadSafe $true -Path $phpPath
$phpVersion = Get-Php -Path $phpPath
try {
Install-PhpExtension -Path $phpPath -Extension xdebug -Version 2.6 -DontEnable
Move-Item -LiteralPath (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug.dll') -Destination (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.6')
Install-PhpExtension -Path $phpPath -Extension xdebug -Version 2.7 -MinimumStability alpha -DontEnable
Move-Item -LiteralPath (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug.dll') -Destination (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.7')
Move-Item -LiteralPath (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.6') -Destination (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.6.dll')
Move-Item -LiteralPath (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.7') -Destination (Join-Path -Path $phpVersion.ExtensionsPath -ChildPath 'php_xdebug-2.7.dll')
{ Enable-PhpExtension -Path $phpPath -Extension xdebug } | Should -Throw
{ Enable-PhpExtension -Path $phpPath -Extension 'xdebug:2.6' } | Should -Not -Throw
Disable-PhpExtension -Path $phpPath -Extension xdebug
{ Enable-PhpExtension -Path $phpPath -Extension 'xdebug:2.7' } | Should -Not -Throw
} finally {
try {
Remove-Item -LiteralPath $phpPath -Recurse
} catch {
}
}
}
} finally {
foreach ($testCase in $testCases) {
if (Test-Path -LiteralPath $testCase.path) {
try {
Remove-Item -LiteralPath $testCase.path -Recurse
} catch {
}
}
}
}
}