2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 13:47:15 +08:00

fix: tests

This commit is contained in:
2025-12-02 02:00:58 +08:00
parent b8fa605752
commit 4ff1c865ed
2 changed files with 17 additions and 20 deletions

View File

@@ -637,26 +637,33 @@ func (v *baseVhost) SetRedirects(redirects []types.Redirect) error {
// ========== PHPVhost ==========
func (v *PHPVhost) PHP() uint {
directives, err := v.parser.Find("server.include")
phpConf := filepath.Join(v.configDir, "vhost", "010-php.conf")
content, err := os.ReadFile(phpConf)
if err != nil {
return 0
}
var result uint
for _, dir := range directives {
if slices.ContainsFunc(v.parser.parameters2Slices(dir.GetParameters()), func(s string) bool {
return strings.HasPrefix(s, "enable-php-") && strings.HasSuffix(s, ".conf")
}) {
_, _ = fmt.Sscanf(dir.GetParameters()[0].GetValue(), "enable-php-%d.conf", &result)
}
_, err = fmt.Sscanf(strings.TrimSpace(string(content)), "include enable-php-%d.conf;", &result)
if err != nil {
return 0
}
return result
}
func (v *PHPVhost) SetPHP(version uint) error {
// TODO 需要重写逻辑
return fmt.Errorf("not implemented")
if version == 0 {
return os.Remove(filepath.Join(v.configDir, "vhost", "010-php.conf"))
}
phpConf := filepath.Join(v.configDir, "vhost", "010-php.conf")
content := fmt.Sprintf("include enable-php-%d.conf;\n", version)
if err := os.WriteFile(phpConf, []byte(content), 0644); err != nil {
return fmt.Errorf("failed to write php config: %w", err)
}
return nil
}
// ========== ProxyVhost ==========

View File

@@ -186,17 +186,7 @@ func (s *VhostTestSuite) TestPHP() {
s.Equal(uint(0), s.vhost.PHP())
s.NoError(s.vhost.SetPHP(84))
// Nginx 的 PHP 实现使用 include 文件
includes := s.vhost.Includes()
found := false
for _, inc := range includes {
if strings.Contains(inc.Path, "enable-php-84.conf") {
found = true
break
}
}
s.True(found, "PHP include file should exist")
s.Equal(uint(84), s.vhost.PHP())
s.NoError(s.vhost.SetPHP(0))
}