Completed
Pull Request — master (#444)
by Yanick
13:59
created

LiteSpeedTest::getHostName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test;
13
14
use FOS\HttpCache\ProxyClient\HttpDispatcher;
15
use FOS\HttpCache\ProxyClient\LiteSpeed;
16
use FOS\HttpCache\ProxyClient\Nginx;
17
use FOS\HttpCache\Test\Proxy\LiteSpeedProxy;
18
use FOS\HttpCache\Test\Proxy\NginxProxy;
19
20
// TODO: update docs in case anything is configurable
21
/**
22
 * Starts and clears the LiteSpeed proxy between tests.
23
 */
24
trait LiteSpeedTest
25
{
26
    /**
27
     * @var LiteSpeed
28
     */
29
    protected $proxyClient;
30
31
    /**
32
     * @var LiteSpeedProxy
33
     */
34
    protected $proxy;
35
36
    protected function setUp()
37
    {
38
        $this->getProxy()->clear();
39
    }
40
41
    protected function tearDown()
42
    {
43
        $this->getProxy()->stop();
44
    }
45
46
    /**
47
     * Defaults to "lswsctrl".
48
     *
49
     * @return string
50
     */
51
    protected function getBinary()
52
    {
53
        return defined('LITESPEED_BINARY') ? LITESPEED_BINARY : null;
54
    }
55
56
57
    /**
58
     * Defaults to 80.
59
     *
60
     * @return int
61
     */
62
    protected function getCachingProxyPort()
63
    {
64
        return defined('LITESPEED_PORT') ? LITESPEED_PORT : 80;
65
    }
66
67
    /**
68
     * Get the hostname where your application can be reached.
69
     *
70
     * @throws \Exception
71
     *
72
     * @return string
73
     */
74
    protected function getHostName()
75
    {
76
        // @codeCoverageIgnoreStart
77
        if (!defined('WEB_SERVER_HOSTNAME')) {
78
            throw new \Exception(
79
                'To use this test, you need to define the WEB_SERVER_HOSTNAME constant in your phpunit.xml'
80
            );
81
        }
82
        // @codeCoverageIgnoreEnd
83
84
        return WEB_SERVER_HOSTNAME;
85
    }
86
87
    /**
88
     * @return LiteSpeedProxy
89
     */
90
    protected function getProxy()
91
    {
92
        if (null === $this->proxy) {
93
            $this->proxy = new LiteSpeedProxy();
94
            $this->proxy->setPort($this->getCachingProxyPort());
95
96
            if ($this->getBinary()) {
97
                $this->proxy->setBinary($this->getBinary());
98
            }
99
        }
100
101
        return $this->proxy;
102
    }
103
104
    /**
105
     * Get proxy client.
106
     *
107
     * @return LiteSpeed
108
     */
109
    protected function getProxyClient($purgeLocation = '')
0 ignored issues
show
Unused Code introduced by
The parameter $purgeLocation is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110
    {
111
        if (null === $this->proxyClient) {
112
            $httpDispatcher = new HttpDispatcher(
113
                ['http://127.0.0.1']
114
            );
115
116
            $this->proxyClient = new LiteSpeed($httpDispatcher, [
117
                'document_root' => '/usr/local/lsws/DEFAULT/html',
118
            ]);
119
        }
120
121
        return $this->proxyClient;
122
    }
123
}
124