diff --git a/docker-compose.yml b/docker-compose.yml index 6a5b27d483..cf7402ef0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -44,6 +44,7 @@ services: SMTP_PORT: 1025 SMTP_USER: ~ SMTP_PASSWORD: ~ + TEST_MAILCATCHER_URL: "http://mailcatcher:1080" networks: - backend diff --git a/eccube_install.sh b/eccube_install.sh index d21cbb13df..81290dd605 100755 --- a/eccube_install.sh +++ b/eccube_install.sh @@ -210,6 +210,7 @@ defined('SMTP_HOST') or define('SMTP_HOST', '${SMTP_HOST}'); defined('SMTP_PORT') or define('SMTP_PORT', '${SMTP_PORT}'); defined('SMTP_USER') or define('SMTP_USER', '${SMTP_USER}'); defined('SMTP_PASSWORD') or define('SMTP_PASSWORD', '${SMTP_PASSWORD}'); +defined('TEST_MAILCATCHER_URL') or define('TEST_MAILCATCHER_URL', '${TEST_MAILCATCHER_URL-"http://127.0.0.1:1080"}'); __EOF__ diff --git a/tests/class/Common_TestCase.php b/tests/class/Common_TestCase.php index f3e006a132..770115ca1b 100644 --- a/tests/class/Common_TestCase.php +++ b/tests/class/Common_TestCase.php @@ -18,9 +18,6 @@ */ class Common_TestCase extends PHPUnit_Framework_TestCase { - /** MailCatcher の URL. */ - const MAILCATCHER_URL = 'http://127.0.0.1:1080'; - /** * MDB2 をグローバル変数のバックアップ対象から除外する。 * @@ -49,6 +46,9 @@ protected function setUp() $this->objQuery = SC_Query_Ex::getSingletonInstance('', true); $this->objQuery->begin(); $this->objGenerator = new \Eccube2\Tests\Fixture\Generator($this->objQuery); + if (!defined('TEST_MAILCATCHER_URL')) { + $this->markTestSkipped('TEST_MAILCATCHER_URL is not defined.'); + } } protected function tearDown() @@ -77,14 +77,18 @@ protected function checkMailCatcherStatus() $context = stream_context_create(array( 'http' => array('ignore_errors' => true) )); - $response = file_get_contents(self::MAILCATCHER_URL.'/messages', false, $context); + $response = file_get_contents(TEST_MAILCATCHER_URL.'/messages', false, $context); $http_status = strpos($http_response_header[0], '200'); if ($http_status === false) { - $this->markTestSkipped('MailCatcher is not available'); + throw new Exception('Response code is not 200: $http_response_header[0] = ' . var_export($http_response_header[0], true)); + } + + if ($response === false) { + throw new Exception('file_get_contents response is false.'); } } catch (Exception $e) { - $this->markTestSkipped('MailCatcher is not available'); + $this->markTestSkipped('MailCatcher is not available: ' . $e->getMessage()); } } @@ -102,7 +106,7 @@ protected function resetEmails() ) ); - file_get_contents(self::MAILCATCHER_URL.'/messages', false, $context); + file_get_contents(TEST_MAILCATCHER_URL.'/messages', false, $context); } catch (\Exception $e) { // quiet @@ -116,7 +120,7 @@ protected function resetEmails() */ protected function getMailCatcherMessages() { - return json_decode(file_get_contents(self::MAILCATCHER_URL. '/messages'), true); + return json_decode(file_get_contents(TEST_MAILCATCHER_URL. '/messages'), true); } /** @@ -127,7 +131,7 @@ protected function getMailCatcherMessages() */ protected function getMailCatcherMessage($message) { - $source = file_get_contents(self::MAILCATCHER_URL. '/messages/'.$message['id'].'.source'); + $source = file_get_contents(TEST_MAILCATCHER_URL. '/messages/'.$message['id'].'.source'); $message['source'] = quoted_printable_decode($source); $message['source'] = mb_convert_encoding($message['source'], 'UTF-8', 'JIS'); diff --git a/tests/class/SC_SendMailTest.php b/tests/class/SC_SendMailTest.php index 05324789a7..409337b8af 100644 --- a/tests/class/SC_SendMailTest.php +++ b/tests/class/SC_SendMailTest.php @@ -167,15 +167,8 @@ public function testGetBackendParams() $this->verify(); $this->expected = [ - 'host' => '127.0.0.1', - 'port' => '1025' - ]; - $this->actual = $this->objSendMail->getBackendParams('smtp'); - $this->verify(); - - $this->expected = [ - 'host' => '127.0.0.1', - 'port' => '1025' + 'host' => SMTP_HOST, + 'port' => SMTP_PORT, ]; $this->actual = $this->objSendMail->getBackendParams('smtp'); $this->verify();