Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PhpserverTest.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Phpserver;
7 
18 class PhpserverTest extends \PHPUnit\Framework\TestCase
19 {
20  const BASE_URL = '127.0.0.1:8082';
21 
22  private static $serverPid;
23 
27  private $httpClient;
28 
32  public static function setUpBeforeClass()
33  {
34  if (!(defined('TRAVIS') && TRAVIS === true)) {
35  self::markTestSkipped('Travis environment test');
36  }
37  $return = [];
38 
39  $baseDir = __DIR__ . '/../../../../../../';
40  $command = sprintf(
41  'cd %s && php -S %s -t ./pub/ ./phpserver/router.php >/dev/null 2>&1 & echo $!',
42  $baseDir,
43  static::BASE_URL
44  );
45  exec($command, $return);
46  static::$serverPid = (int) $return[0];
47  }
48 
49  private function getUrl($url)
50  {
51  return sprintf('http://%s/%s', self::BASE_URL, ltrim($url, '/'));
52  }
53 
54  public function setUp()
55  {
56  $this->httpClient = new \Zend\Http\Client(null, ['timeout' => 10]);
57  }
58 
59  public function testServerHasPid()
60  {
61  $this->assertTrue(static::$serverPid > 0);
62  }
63 
64  public function testServerResponds()
65  {
66  $this->httpClient->setUri($this->getUrl('/'));
67  $response = $this->httpClient->send();
68  $this->assertFalse($response->isClientError());
69  }
70 
71  public function testStaticCssFile()
72  {
73  $this->httpClient->setUri($this->getUrl('/errors/default/css/styles.css'));
74  $response = $this->httpClient->send();
75 
76  $this->assertFalse($response->isClientError());
77  $this->assertStringStartsWith('text/css', $response->getHeaders()->get('Content-Type')->getMediaType());
78  }
79 
80  public function testStaticImageFile()
81  {
82  $this->httpClient->setUri($this->getUrl('/errors/default/images/logo.gif'));
83  $response = $this->httpClient->send();
84 
85  $this->assertFalse($response->isClientError());
86  $this->assertStringStartsWith('image/gif', $response->getHeaders()->get('Content-Type')->getMediaType());
87  }
88 
89  public static function tearDownAfterClass()
90  {
91  posix_kill(static::$serverPid, SIGKILL);
92  }
93 }
$response
Definition: 404.php:11
exec($command, array &$output=null, &$return_var=null)
$baseDir
Definition: autoload.php:9
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60