/
phpunit.go
55 lines (46 loc) · 1.6 KB
/
phpunit.go
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
package nightwatch
import (
"fmt"
"github.com/blang/semver"
"github.com/ironstar-io/tokaido/services/composer"
"github.com/ironstar-io/tokaido/system/console"
"github.com/ironstar-io/tokaido/utils"
)
var validPHPUnitRange = ">=6.x.x <7.0.0"
var phpUnit = "phpunit/phpunit"
func upgradePHPUnit(currentVersion string) {
console.Println("🐘 Tokaido detected you're running version "+currentVersion+" of PHPUnit, which isn't compatible with Drupal Nightwatch.\n", "")
confirmUpdate := utils.ConfirmationPrompt("Would you like us to attempt to update it for you automatically with composer?", "y")
if confirmUpdate == false {
fmt.Println("We'll still attempt to run the tests, but they make not behave as expected!")
return
}
composer.RemovePackage([]string{"--dev", phpUnit})
composer.RequirePackage([]string{"--dev", phpUnit, "^6.5"})
}
func installPHPUnit() {
console.Println("🐘 Tokaido was unable to detect an installation of PHPUnit, which is required for Drupal Nightwatch.\n", "")
confirmUpdate := utils.ConfirmationPrompt("Would you like us to attempt to install it for you automatically with composer?", "y")
if confirmUpdate == false {
fmt.Println("We'll still attempt to run the tests, but they make not behave as expected!")
return
}
composer.RequirePackage([]string{"--dev", phpUnit, "^6.5"})
}
func checkPHPUnit() {
v, err := composer.FindPackageVersion(phpUnit)
if err != nil {
installPHPUnit()
return
}
if v == "" {
installPHPUnit()
return
}
ps, _ := semver.Parse(v)
validRange, _ := semver.ParseRange(validPHPUnitRange)
if !validRange(ps) {
upgradePHPUnit(v)
return
}
}