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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Phpserver;
/**
* @magentoAppIsolation enabled
*
* @magentoConfigFixture current_store web/secure/base_url http://127.0.0.1:8082/
* @magentoConfigFixture current_store web/unsecure/base_link_url http://127.0.0.1:8082/
* @magentoConfigFixture current_store web/secure/base_link_url http://127.0.0.1:8082/
* @magentoConfigFixture current_store web/secure/use_in_frontend 0
*
* @magentoAppArea frontend
*/
class PhpserverTest extends \PHPUnit\Framework\TestCase
{
const BASE_URL = '127.0.0.1:8082';
private static $serverPid;
/**
* @var \Zend\Http\Client
*/
private $httpClient;
/**
* Instantiate phpserver in the pub folder
*/
public static function setUpBeforeClass()
{
if (!(defined('TRAVIS') && TRAVIS === true)) {
self::markTestSkipped('Travis environment test');
}
$return = [];
$baseDir = __DIR__ . '/../../../../../../';
$command = sprintf(
'cd %s && php -S %s -t ./pub/ ./phpserver/router.php >/dev/null 2>&1 & echo $!',
$baseDir,
static::BASE_URL
);
exec($command, $return);
static::$serverPid = (int) $return[0];
}
private function getUrl($url)
{
return sprintf('http://%s/%s', self::BASE_URL, ltrim($url, '/'));
}
public function setUp()
{
$this->httpClient = new \Zend\Http\Client(null, ['timeout' => 10]);
}
public function testServerHasPid()
{
$this->assertTrue(static::$serverPid > 0);
}
public function testServerResponds()
{
$this->httpClient->setUri($this->getUrl('/'));
$response = $this->httpClient->send();
$this->assertFalse($response->isClientError());
}
public function testStaticCssFile()
{
$this->httpClient->setUri($this->getUrl('/errors/default/css/styles.css'));
$response = $this->httpClient->send();
$this->assertFalse($response->isClientError());
$this->assertStringStartsWith('text/css', $response->getHeaders()->get('Content-Type')->getMediaType());
}
public function testStaticImageFile()
{
$this->httpClient->setUri($this->getUrl('/errors/default/images/logo.gif'));
$response = $this->httpClient->send();
$this->assertFalse($response->isClientError());
$this->assertStringStartsWith('image/gif', $response->getHeaders()->get('Content-Type')->getMediaType());
}
public static function tearDownAfterClass()
{
posix_kill(static::$serverPid, SIGKILL);
}
}