Completed
Pull Request — master (#444)
by Yanick
02:55
created

LiteSpeedTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
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\Test\Proxy\LiteSpeedProxy;
17
18
/**
19
 * Starts and clears the LiteSpeed proxy between tests.
20
 */
21
trait LiteSpeedTest
22
{
23
    /**
24
     * @var LiteSpeed
25
     */
26
    protected $proxyClient;
27
28
    /**
29
     * @var LiteSpeedProxy
30
     */
31
    protected $proxy;
32
33
    protected function setUp()
34
    {
35
        $this->getProxy()->clear();
36
    }
37
38
    protected function tearDown()
39
    {
40
        // Comment this out if you want to check the whole
41
        // error.log
42
        // Otherwise you'll get a new error.log for every
43
        // test run and thus only the log of the last
44
        // test will be visible.
45
        // $this->getProxy()->stop();
46
    }
47
48
    /**
49
     * Defaults to "/usr/local/lsws/bin/lswsctrl".
50
     *
51
     * @return string
52
     */
53
    protected function getBinary()
54
    {
55
        return defined('LITESPEED_BINARY') ? LITESPEED_BINARY : null;
56
    }
57
58
    /**
59
     * Defaults to 80.
60
     *
61
     * @return int
62
     */
63
    protected function getCachingProxyPort()
64
    {
65
        return defined('LITESPEED_PORT') ? LITESPEED_PORT : 8089; // 8088 is used by nginx
66
    }
67
68
    /**
69
     * Get the hostname where your application can be reached.
70
     *
71
     * @throws \Exception
72
     *
73
     * @return string
74
     */
75
    protected function getHostName()
76
    {
77
        // @codeCoverageIgnoreStart
78
        if (!defined('WEB_SERVER_HOSTNAME')) {
79
            throw new \Exception(
80
                'To use this test, you need to define the WEB_SERVER_HOSTNAME constant in your phpunit.xml'
81
            );
82
        }
83
        // @codeCoverageIgnoreEnd
84
85
        return WEB_SERVER_HOSTNAME;
86
    }
87
88
    /**
89
     * @return LiteSpeedProxy
90
     */
91
    protected function getProxy()
92
    {
93
        if (null === $this->proxy) {
94
            $this->proxy = new LiteSpeedProxy();
95
            $this->proxy->setPort($this->getCachingProxyPort());
96
97
            if ($this->getBinary()) {
98
                $this->proxy->setBinary($this->getBinary());
99
            }
100
        }
101
102
        return $this->proxy;
103
    }
104
105
    /**
106
     * Get proxy client.
107
     *
108
     * @return LiteSpeed
109
     */
110 View Code Duplication
    protected function getProxyClient()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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