|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\Phpserver; |
| 7 | + |
| 8 | +/** |
| 9 | + * @magentoAppIsolation enabled |
| 10 | + * |
| 11 | + * @magentoConfigFixture current_store web/secure/base_url http://127.0.0.1:8082/ |
| 12 | + * @magentoConfigFixture current_store web/unsecure/base_link_url http://127.0.0.1:8082/ |
| 13 | + * @magentoConfigFixture current_store web/secure/base_link_url http://127.0.0.1:8082/ |
| 14 | + * @magentoConfigFixture current_store web/secure/use_in_frontend 0 |
| 15 | + * |
| 16 | + * @magentoAppArea frontend |
| 17 | + */ |
| 18 | +class PhpserverTest extends \PHPUnit\Framework\TestCase |
| 19 | +{ |
| 20 | + const BASE_URL = '127.0.0.1:8082'; |
| 21 | + |
| 22 | + private static $serverPid; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var \Zend\Http\Client |
| 26 | + */ |
| 27 | + private $httpClient; |
| 28 | + |
| 29 | + /** |
| 30 | + * Instantiate phpserver in the pub folder |
| 31 | + */ |
| 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 | +} |
0 commit comments