Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/actions/ini/add.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Select-ExtensionPackageLink {
$extensionLinks |
Select-Object -First $Global:PVMConfig.env.DEFAULT_PARTIAL_LIST_SIZE |
Group-Object { $_.extVersion } |
Sort-Object -Descending -Property @{ Expression = { Get-PrereleaseSortKey -Name $_.Name } } |
Sort-Object -Descending -Property @{ Expression = { Get-PrereleaseSortKey -name $_.Name } } |
ForEach-Object -Process {
$sortedGroup = $_.Group | Sort-Object -Property `
@{ Expression = { $_.buildType -eq 'NTS' }; Descending = $true },
Expand Down Expand Up @@ -46,21 +46,21 @@ function Select-ExtensionPackageLink {
}

function Get-PrereleaseSortKey {
param ($Name)
param ($name)

$baseVersionParts = ($Name -replace '(alpha|beta|rc).*', '') -split '\.'
$baseVersionParts = ($name -replace '(alpha|beta|rc).*', '') -split '\.'
[int64]$versionScore = 0
for ($i = 0; $i -lt 3; $i++) {
$part = if ($i -lt $baseVersionParts.Count) { [int64]$baseVersionParts[$i] } else { 0 }
$versionScore = ($versionScore * 1000) + $part
}

$weight = if ($Name -match 'alpha') { 1 }
elseif ($Name -match 'beta') { 2 }
elseif ($Name -match 'rc') { 3 }
$weight = if ($name -match 'alpha') { 1 }
elseif ($name -match 'beta') { 2 }
elseif ($name -match 'rc') { 3 }
else { 4 } # stable

$number = if ($Name -match '(alpha|beta|rc)(\d+)') { [int64]$matches[2] } else { 9999 }
$number = if ($name -match '(alpha|beta|rc)(\d+)') { [int64]$matches[2] } else { 9999 }

return ($versionScore * 100000) + ($weight * 10000) + $number
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/ini/ext.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Show-PHPExtensionInfo {
$linksMatchingExtName = Get-ExtensionMatchingCategories -extName $searchId
$availableMatch = Select-ExtensionFromMatches -linksMatchingExtName $linksMatchingExtName

$matchesListStatus = Get-MatchingPHPExtensionsStatus -iniPath $iniPath -extName $searchId -includeIniOnly $true # | Select-Object -First 1
$matchesListStatus = Get-MatchingPHPExtensionsStatus -iniPath $iniPath -extName $searchId -includeIniOnly $true

if ($matchesListStatus.Length -gt 1) {
Show-Info -message "`nMultiple extensions match '$extName':`n"
Expand Down
16 changes: 8 additions & 8 deletions src/actions/ini/helpers/fetch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ function Get-ExtensionHandlers {

try {
# Remove existing xdebug config using the config functions
$xdebugV2Config = Get-XdebugConfigV2 -XDebugPath $fileName
$xdebugV3Config = Get-XdebugConfigV3 -XDebugPath $fileName
$xdebugV2Config = Get-XdebugConfigV2 -dllPath $fileName
$xdebugV3Config = Get-XdebugConfigV3 -dllPath $fileName

$lines = Get-ContentWrapper -path $iniPath
$newLines = @()
Expand Down Expand Up @@ -194,9 +194,9 @@ function Get-ExtensionHandlers {
Set-ContentWrapper -path $iniPath -value $newLines

# Add new xdebug config
$xDebugConfig = Get-XdebugConfigV2 -XDebugPath $fileName
$xDebugConfig = Get-XdebugConfigV2 -dllPath $fileName
if ($extVersion -like '3.*') {
$xDebugConfig = Get-XdebugConfigV3 -XDebugPath $fileName
$xDebugConfig = Get-XdebugConfigV3 -dllPath $fileName
}
$xDebugConfig = "`n$($xDebugConfig -join "`n")"
Add-ContentWrapper -path $iniPath -value $xDebugConfig
Expand Down Expand Up @@ -287,23 +287,23 @@ function Get-XDebugFromUrl {
}

function Get-XdebugConfigV2 {
param ($XDebugPath)
param ($dllPath)

return @(
'[xdebug]'
";zend_extension='$XDebugPath'"
";zend_extension='$dllPath'"
'xdebug.remote_enable=1'
'xdebug.remote_host=127.0.0.1'
'xdebug.remote_port=9000'
)
}

function Get-XdebugConfigV3 {
param ($XDebugPath)
param ($dllPath)

return @(
'[xdebug]'
";zend_extension='$XDebugPath'"
";zend_extension='$dllPath'"
'xdebug.mode=debug'
'xdebug.client_host=127.0.0.1'
'xdebug.client_port=9003'
Expand Down
2 changes: 1 addition & 1 deletion src/actions/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function Get-PHP {
foreach ($key in $urls.Keys) {
$_url = $urls[$key]
$downloadUrl = "$_url/$fileName"
$downloadedFilePath = Get-PHPFromUrl -destination $destination -url $downloadUrl -version $versionObject
$downloadedFilePath = Get-PHPFromUrl -destination $destination -url $downloadUrl -versionObject $versionObject
if ($downloadedFilePath) {
return @{ pvmData = $downloadedFilePath }
}
Expand Down
2 changes: 1 addition & 1 deletion src/actions/log.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function Get-LogEntries {
}

# Format the timestamp nicely
$niceTime = Format-NiceTimestamp $timestamp
$niceTime = Format-NiceTimestamp -timestamp $timestamp

$parsedEntries += @{
Timestamp = $timestamp
Expand Down
2 changes: 1 addition & 1 deletion src/actions/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function Save-PHPProfile {
}

# Get current PHP configuration
$phpIniData = Get-PHPData -PhpIniPath $iniPath
$phpIniData = Get-PHPData -phpIniPath $iniPath

# Build profile structure
$userProfile = [ordered]@{
Expand Down
2 changes: 1 addition & 1 deletion src/actions/setup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Initialize-PVM {
function Initialize-PVMDirectories {
$dirs = @(
$Global:PVMConfig.paths.directories.storage,
$Global:PVMConfig.paths.directories.fakeStorage,
$Global:PVMConfig.paths.directories.testDrive,
$Global:PVMConfig.paths.directories.php,
$Global:PVMConfig.paths.directories.data,
$Global:PVMConfig.paths.directories.templates,
Expand Down
27 changes: 21 additions & 6 deletions src/actions/test.ps1
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@

function Initialize-PVMTestEnvironment {
function Initialize-TestEnvironment {
param ($driveName)

$environment = @{
PVMConfigBackup = Copy-ObjectDeep -object $Global:PVMConfig
TestDrive = "$($Global:PVMConfig.paths.directories.fakeStorage)\$driveName-drive"
TestDrive = "$($Global:PVMConfig.paths.directories.testDrive)\$driveName-drive"
}

Clear-PVMTestStorage
Set-FakePaths -root $environment.TestDrive
Set-TestDrive -path $environment.TestDrive

New-Directory -path $environment.TestDrive
$created = New-Directory -path $environment.TestDrive
if ($created -ne 0) {
$Global:PVMConfig = $environment.PVMConfigBackup
return $null
}

$Global:CurrentTestDrive = $environment.TestDrive

return $environment
}

function Restore-PVMTestEnvironment {
function Restore-TestEnvironment {
param ($environment)

Remove-ItemWrapper -path $environment.TestDrive
$Global:PVMConfig = $environment.PVMConfigBackup
$Global:CurrentTestDrive = $null
}

function Get-PowerShellInfo {
Expand Down Expand Up @@ -76,6 +82,11 @@ function Invoke-TestFile {
}

try {
$testEnvironment = Initialize-TestEnvironment -driveName ($file.BaseName -replace '\.tests$', '')
if (-not $testEnvironment) {
throw 'Failed to create test drive!'
}

$config.Run.Path = $file.FullName
$config.Run.PassThru = $true
$testResult = Invoke-Pester -Configuration $config
Expand Down Expand Up @@ -108,6 +119,8 @@ function Invoke-TestFile {
} catch {
$null = Add-LogEntry -data @{ header = "$($MyInvocation.MyCommand.Name) - Failed to run test: $($file.FullName)"; exception = $_ }
return @{ code = -1; name = $file.Name; relativeFilePath = $relativeFilePath; sortedName = $sortedName; message = @{ content = 'Failed to run test, check log.'; color = 'DarkYellow' }; testResultData = $testResultData }
} finally {
if ($testEnvironment) { Restore-TestEnvironment -environment $testEnvironment }
}
}

Expand Down Expand Up @@ -165,9 +178,11 @@ function Invoke-Tests {

Show-Info -message "`nRunning tests with verbosity: $($options.verbosity)"

Clear-TestDrive
$testSummary = $tests | ForEach-Object -Process {
Invoke-TestFile -config $config -file $_ -options $options -separatorWidth $separatorWidth -testsMap $testsMap
}
Clear-TestDrive

$maxLineLength = ($testSummary.relativeFilePath | Measure-Object -Maximum Length).Maximum + ($Global:PVMConfig.env.MIN_PAD_RIGHT_LENGTH * 3)

Expand Down
61 changes: 42 additions & 19 deletions src/helpers/config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ function Get-EnvInt {
return $default
}

function Get-EnvPath {
param ($value, $default)

if ($null -ne $value) { $value = $value.Trim() }

$isValidPathFormat = -not [string]::IsNullOrWhiteSpace($value) `
-and $value -match '^[A-Za-z]+:' `
-and $value.IndexOfAny([System.IO.Path]::GetInvalidPathChars()) -eq -1

if (-not $isValidPathFormat) {
return $default
}

return $value
}

function Get-EnvConfig {
param ($rootPath)

Expand Down Expand Up @@ -124,26 +140,33 @@ function Get-EnvConfig {
return $config
}

function Get-EnvDefaults {
return @{
PHP_CURRENT_VERSION_PATH = 'C:\pvm\php'
PVM_ENV_VAR_NAME = 'PVM'
CACHE_MAX_HOURS = 168
DEFAULT_LOG_PAGE_SIZE = 5
DEFAULT_PARTIAL_LIST_SIZE = 10
MIN_PAD_RIGHT_LENGTH = 10
MIN_LINE_LENGTH = 50
ENABLE_UPDATE_CHECK = $true
UPDATE_CHECK_INTERVAL_HOURS = 24
SOUNDS_DISABLED = $false
}
}

function Get-Config {
param ($rootPath)

$envConfig = Get-EnvConfig -rootPath $rootPath
$envDefaults = Get-EnvDefaults

$storage = "$rootPath\storage"
$data = "$storage\data"
$profiles = "$data\profiles"
$templates = "$data\templates"
$logs = "$storage\logs"
$state = "$data\state"
$fakeStorage = $envConfig['TEST_DRIVE']

$isValidPathFormat = -not [string]::IsNullOrWhiteSpace($fakeStorage) `
-and $fakeStorage -match '^[A-Za-z]+:' `
-and $fakeStorage.IndexOfAny([System.IO.Path]::GetInvalidPathChars()) -eq -1

if (-not $isValidPathFormat) {
$fakeStorage = "$storage\tests"
}

return @{
version = '2.7' # PVM version
Expand All @@ -154,7 +177,7 @@ function Get-Config {
directories = @{
root = $rootPath
storage = $storage
fakeStorage = $fakeStorage
testDrive = Get-EnvPath -value $envConfig['TEST_DRIVE'] -default "$storage\tests"
php = "$storage\php"
data = $data
templates = $templates
Expand Down Expand Up @@ -190,16 +213,16 @@ function Get-Config {
}

env = [ordered]@{
PHP_CURRENT_VERSION_PATH = $envConfig['PHP_CURRENT_VERSION_PATH']
PHP_CURRENT_VERSION_PATH = Get-EnvPath -value $envConfig['PHP_CURRENT_VERSION_PATH'] -default $envDefaults.PHP_CURRENT_VERSION_PATH
PVM_ENV_VAR_NAME = $envConfig['PVM_ENV_VAR_NAME']
CACHE_MAX_HOURS = Get-EnvInt -value $envConfig['CACHE_MAX_HOURS'] -default 168
DEFAULT_LOG_PAGE_SIZE = Get-EnvInt -value $envConfig['DEFAULT_LOG_PAGE_SIZE'] -default 5
DEFAULT_PARTIAL_LIST_SIZE = Get-EnvInt -value $envConfig['DEFAULT_PARTIAL_LIST_SIZE'] -default 10
MIN_PAD_RIGHT_LENGTH = Get-EnvInt -value $envConfig['MIN_PAD_RIGHT_LENGTH'] -default 10
MIN_LINE_LENGTH = Get-EnvInt -value $envConfig['MIN_LINE_LENGTH'] -default 50
ENABLE_UPDATE_CHECK = Get-EnvBool -value $envConfig['ENABLE_UPDATE_CHECK'] -default $true
UPDATE_CHECK_INTERVAL_HOURS = Get-EnvInt -value $envConfig['UPDATE_CHECK_INTERVAL_HOURS'] -default 24
SOUNDS_DISABLED = Get-EnvBool -value $envConfig['SOUNDS_DISABLED'] -default $false
CACHE_MAX_HOURS = Get-EnvInt -value $envConfig['CACHE_MAX_HOURS'] -default $envDefaults.CACHE_MAX_HOURS
DEFAULT_LOG_PAGE_SIZE = Get-EnvInt -value $envConfig['DEFAULT_LOG_PAGE_SIZE'] -default $envDefaults.DEFAULT_LOG_PAGE_SIZE
DEFAULT_PARTIAL_LIST_SIZE = Get-EnvInt -value $envConfig['DEFAULT_PARTIAL_LIST_SIZE'] -default $envDefaults.DEFAULT_PARTIAL_LIST_SIZE
MIN_PAD_RIGHT_LENGTH = Get-EnvInt -value $envConfig['MIN_PAD_RIGHT_LENGTH'] -default $envDefaults.MIN_PAD_RIGHT_LENGTH
MIN_LINE_LENGTH = Get-EnvInt -value $envConfig['MIN_LINE_LENGTH'] -default $envDefaults.MIN_LINE_LENGTH
ENABLE_UPDATE_CHECK = Get-EnvBool -value $envConfig['ENABLE_UPDATE_CHECK'] -default $envDefaults.ENABLE_UPDATE_CHECK
UPDATE_CHECK_INTERVAL_HOURS = Get-EnvInt -value $envConfig['UPDATE_CHECK_INTERVAL_HOURS'] -default $envDefaults.UPDATE_CHECK_INTERVAL_HOURS
SOUNDS_DISABLED = Get-EnvBool -value $envConfig['SOUNDS_DISABLED'] -default $envDefaults.SOUNDS_DISABLED
}

constants = [ordered]@{
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/io.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function Test-FileNotExists {
function Test-PathExists {
param ($path)

return (Test-DirectoryExists $path) -or (Test-FileExists $path)
return (Test-DirectoryExists -path $path) -or (Test-FileExists -path $path)
}

function Test-PathNotExists {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/php.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ function Get-ZendExtensionsInfo {
}

function Get-PHPData {
param ($PhpIniPath)
param ($phpIniPath)

$iniContent = Get-ContentWrapper -path $PhpIniPath
$iniContent = Get-ContentWrapper -path $phpIniPath

$phpIniData = @{
extensions = @()
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ function Show-Scripts {
}
}

function Clear-PVMTestStorage {
Remove-ItemWrapper -path "$($Global:PVMConfig.paths.directories.fakeStorage)\*"
function Clear-TestDrive {
Remove-ItemWrapper -path "$($Global:PVMConfig.paths.directories.testDrive)\*"
}

function Use-PesterVersion {
Expand Down Expand Up @@ -364,28 +364,28 @@ function Get-SortedTests {
return $data
}

function Set-FakePaths {
param ($root)
function Set-TestDrive {
param ($path)

$fakeStorage = "$root\storage"
$fakeStorage = "$path\storage"
$fakeData = "$fakeStorage\data"
$fakeProfiles = "$fakeData\profiles"
$fakeTemplates = "$fakeData\templates"
$fakeLogs = "$fakeStorage\logs"
$fakeState = "$fakeData\state"

$Global:PVMConfig.rootPath = $root
$Global:PVMConfig.paths.directories.root = $root
$Global:PVMConfig.rootPath = $path
$Global:PVMConfig.paths.directories.root = $path
$Global:PVMConfig.paths.directories.storage = $fakeStorage
$Global:PVMConfig.paths.directories.fakeStorage = $fakeStorage
$Global:PVMConfig.paths.directories.testDrive = $path
$Global:PVMConfig.paths.directories.php = "$fakeStorage\php"
$Global:PVMConfig.paths.directories.data = $fakeData
$Global:PVMConfig.paths.directories.templates = $fakeTemplates
$Global:PVMConfig.paths.directories.cache = "$fakeData\cache"
$Global:PVMConfig.paths.directories.profiles = $fakeProfiles
$Global:PVMConfig.paths.directories.log = $fakeLogs
$Global:PVMConfig.paths.directories.state = $fakeState
$Global:PVMConfig.paths.directories.assets = "$root\assets"
$Global:PVMConfig.paths.directories.assets = "$path\assets"

$Global:PVMConfig.paths.files.profileExample = "$fakeProfiles\profile-example.json"
$Global:PVMConfig.paths.files.profileTemplate = "$fakeTemplates\profile-template.json"
Expand All @@ -396,5 +396,5 @@ function Set-FakePaths {
$Global:PVMConfig.paths.files.pathVarBackup = "$fakeState\path.bak.log"
$Global:PVMConfig.paths.files.lastUpdateCheck = "$fakeState\last_update_check.txt"

$Global:PVMConfig.env.PHP_CURRENT_VERSION_PATH = "$root\pvm\php"
$Global:PVMConfig.env.PHP_CURRENT_VERSION_PATH = "$path\pvm\php"
}
Loading