Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

メール関連の PHPUnit 修正 #998

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ services:
SMTP_PORT: 1025
SMTP_USER: ~
SMTP_PASSWORD: ~
TEST_MAILCATCHER_URL: "http://mailcatcher:1080"
networks:
- backend

Expand Down
1 change: 1 addition & 0 deletions eccube_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down
22 changes: 13 additions & 9 deletions tests/class/Common_TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
*/
class Common_TestCase extends PHPUnit_Framework_TestCase
{
/** MailCatcher の URL. */
const MAILCATCHER_URL = 'http://127.0.0.1:1080';

/**
* MDB2 をグローバル変数のバックアップ対象から除外する。
*
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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');
Expand Down
11 changes: 2 additions & 9 deletions tests/class/SC_SendMailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading