From f00fa655ab874c895fb354dfe4459b2dec5454b9 Mon Sep 17 00:00:00 2001 From: Seasoft Date: Fri, 6 Sep 2024 12:40:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fixed=20EC-CUBE#997=20(SC=5FSendMailTest::t?= =?UTF-8?q?estGetBackendParams()=20=E3=83=86=E3=82=B9=E3=83=88=E9=87=8D?= =?UTF-8?q?=E8=A4=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/class/SC_SendMailTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/class/SC_SendMailTest.php b/tests/class/SC_SendMailTest.php index 05324789a7..25f64b0fbf 100644 --- a/tests/class/SC_SendMailTest.php +++ b/tests/class/SC_SendMailTest.php @@ -172,12 +172,5 @@ public function testGetBackendParams() ]; $this->actual = $this->objSendMail->getBackendParams('smtp'); $this->verify(); - - $this->expected = [ - 'host' => '127.0.0.1', - 'port' => '1025' - ]; - $this->actual = $this->objSendMail->getBackendParams('smtp'); - $this->verify(); } } From 49e834ee527f563215a785e7c3f56c4e440ea3b5 Mon Sep 17 00:00:00 2001 From: Seasoft Date: Fri, 6 Sep 2024 12:44:58 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Docker=20Compose=20=E6=A7=8B=E6=88=90?= =?UTF-8?q?=E3=81=A7=E3=82=82=20PHPUnit=20=E3=81=AE=E3=83=A1=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E9=96=A2=E9=80=A3=E3=81=AE=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A1=8C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 1 + eccube_install.sh | 1 + tests/class/Common_TestCase.php | 22 +++++++++++++--------- tests/class/SC_SendMailTest.php | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) 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 25f64b0fbf..409337b8af 100644 --- a/tests/class/SC_SendMailTest.php +++ b/tests/class/SC_SendMailTest.php @@ -167,8 +167,8 @@ public function testGetBackendParams() $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();