Skip to content

Commit ae8e37c

Browse files
committed
Preparing functional tests for litespeed integration
1 parent 190d39a commit ae8e37c

File tree

6 files changed

+247
-0
lines changed

6 files changed

+247
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ before_script:
6767
- if [ "$VARNISH_MODULES_VERSION" != "" ]; then sh ./tests/install-varnish-modules.sh; fi
6868
# Install NGINX
6969
- sh ./tests/install-nginx.sh
70+
# Install OpenLiteSpeed
71+
- sh ./tests/install-open-litespeed.sh
7072

7173
script:
7274
- composer validate --strict --no-check-lock

src/Test/LiteSpeedTest.php

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
// TODO: update docs in case anything is configurable
19+
/**
20+
* Starts and clears the LiteSpeed proxy between tests.
21+
*/
22+
trait LiteSpeedTest
23+
{
24+
/**
25+
* @var LiteSpeed
26+
*/
27+
protected $proxyClient;
28+
29+
/**
30+
* @var LiteSpeedProxy
31+
*/
32+
protected $proxy;
33+
34+
protected function setUp()
35+
{
36+
$this->getProxy()->clear();
37+
}
38+
39+
protected function tearDown()
40+
{
41+
$this->getProxy()->stop();
42+
}
43+
44+
/**
45+
* Defaults to "lswsctrl".
46+
*
47+
* @return string
48+
*/
49+
protected function getBinary()
50+
{
51+
return defined('LITESPEED_BINARY') ? LITESPEED_BINARY : null;
52+
}
53+
54+
/**
55+
* Defaults to 80.
56+
*
57+
* @return int
58+
*/
59+
protected function getCachingProxyPort()
60+
{
61+
return defined('LITESPEED_PORT') ? LITESPEED_PORT : 80;
62+
}
63+
64+
/**
65+
* Get the hostname where your application can be reached.
66+
*
67+
* @throws \Exception
68+
*
69+
* @return string
70+
*/
71+
protected function getHostName()
72+
{
73+
// @codeCoverageIgnoreStart
74+
if (!defined('WEB_SERVER_HOSTNAME')) {
75+
throw new \Exception(
76+
'To use this test, you need to define the WEB_SERVER_HOSTNAME constant in your phpunit.xml'
77+
);
78+
}
79+
// @codeCoverageIgnoreEnd
80+
81+
return WEB_SERVER_HOSTNAME;
82+
}
83+
84+
/**
85+
* @return LiteSpeedProxy
86+
*/
87+
protected function getProxy()
88+
{
89+
if (null === $this->proxy) {
90+
$this->proxy = new LiteSpeedProxy();
91+
$this->proxy->setPort($this->getCachingProxyPort());
92+
93+
if ($this->getBinary()) {
94+
$this->proxy->setBinary($this->getBinary());
95+
}
96+
}
97+
98+
return $this->proxy;
99+
}
100+
101+
/**
102+
* Get proxy client.
103+
*
104+
* @return LiteSpeed
105+
*/
106+
protected function getProxyClient($purgeLocation = '')
107+
{
108+
if (null === $this->proxyClient) {
109+
$httpDispatcher = new HttpDispatcher(
110+
['http://127.0.0.1']
111+
);
112+
113+
$this->proxyClient = new LiteSpeed($httpDispatcher, [
114+
'document_root' => '/usr/local/lsws/DEFAULT/html',
115+
]);
116+
}
117+
118+
return $this->proxyClient;
119+
}
120+
}

src/Test/LiteSpeedTestCase.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Abstract test that collects traits necessary for running tests against
18+
* LiteSpeed.
19+
*/
20+
abstract class LiteSpeedTestCase extends TestCase
21+
{
22+
use CacheAssertions;
23+
use HttpCaller;
24+
use LiteSpeedTest;
25+
}

src/Test/Proxy/LiteSpeedProxy.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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\Proxy;
13+
14+
class LiteSpeedProxy extends AbstractProxy
15+
{
16+
protected $binary = 'lswsctrl';
17+
18+
protected $port = 80;
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
public function start()
24+
{
25+
$this->runCommand(
26+
$this->getBinary(),
27+
[
28+
'start',
29+
]
30+
);
31+
32+
$this->waitFor($this->getIp(), $this->getPort(), 2000);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function stop()
39+
{
40+
$this->runCommand(
41+
$this->getBinary(),
42+
[
43+
'stop',
44+
]
45+
);
46+
}
47+
48+
/**
49+
* {@inheritdoc}
50+
*/
51+
public function clear()
52+
{
53+
$this->stop();
54+
$this->start();
55+
}
56+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Tests\Functional\ProxyClient;
13+
14+
use FOS\HttpCache\Test\LiteSpeedTestCase;
15+
16+
/**
17+
* @group webserver
18+
* @group litespeed
19+
*/
20+
class LiteSpeedProxyClientTest extends LiteSpeedTestCase
21+
{
22+
use PurgeAssertions;
23+
24+
public function testPurge()
25+
{
26+
$this->assertPurge($this->getProxyClient());
27+
}
28+
29+
public function testPurgeContentType()
30+
{
31+
$this->assertPurgeContentType($this->getProxyClient());
32+
}
33+
34+
public function testPurgeHost()
35+
{
36+
$this->assertPurgeHost($this->getProxyClient(), 'http://localhost:6181');
37+
}
38+
}

tests/install-openlitespeed.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
wget https://openlitespeed.org/packages/openlitespeed-1.4.42.tgz
4+
tar -zxvf openlitespeed-1.4.42.tgz
5+
cd openlitespeed
6+
./install.sh

0 commit comments

Comments
 (0)