LoginSignup
1
0

More than 3 years have passed since last update.

改行コードに関するTipsメモ

Last updated at Posted at 2019-09-05

はじめに

  • 修正したメッセージ文言内容がテストコード上で担保したいため、UTを作成しました
  • 結果、UT失敗して少々つまずいたのでTips的な備忘録として残します
  • IDEは、PhpStormを使用しています

メッセージ本文1行の場合

Productionコード

  • email.php
/**
 * メッセージ本文
 */
$lang['message_body'] = "これはメッセージです!";

テストコード

  • MessageTest.php(dataProviderは省略)
    /**
     * @test
     *
     * @dataProvider createDataProvider
     *
     * @param $param1
     * @param $param2
     * @param $param3
     * @param $expectedResult
     */
    public function testMessage($param1, $param2, $param3, $expectedResult)
    {
        $result = $this->model->createMessage($param2, $param1, $param3);

        foreach ($expectedResult as $key => $expectedValue) {
            $this->assertEquals($expectedValue, $result[$key]);
        }
    }

    /**
     * @param string $param1
     * @param int $param2
     * @param string $param3
     * @param int $id
     *
     * @return string
     */
    private function messageContent($param1, $param2, $param3, $id)
    {
        return "これはメッセージです!";
    }

結果

  • 成功

success.png

メッセージ本文複数行の場合

Productionコード

  • email.php
/**
 * メッセージ本文
 */
$lang['message_body'] = "これはメッセージです!
以上、宜しくお願いいたします。";

テストコード

  • MessageTest.php(dataProviderは省略)
    /**
     * @test
     *
     * @dataProvider createDataProvider
     *
     * @param $bankbook
     * @param $member
     * @param $emoney
     * @param $expectedResult
     */
    public function testMessage($param1, $param2, $param3, $expectedResult)
    {
        $result = $this->model->createMessage($param2, $param1, $param3);

        foreach ($expectedResult as $key => $expectedValue) {
            $this->assertEquals($expectedValue, $result[$key]);
        }
    }

    /**
     * @param string $param1
     * @param int $param2
     * @param string $param3
     * @param int $id
     *
     * @return string
     */
    private function messageContent($param1, $param2, $param3, $id)
    {
        return "これはメッセージです!
以上、宜しくお願いいたします。";
    }

結果

  • 失敗

failer.png

対応策

  • PhpStormの右下の設定で改行コードの設定箇所を変更する
    • デフォルト(CRLF)→ LFに!

change.png

再度実行

  • 成功

succ.png

メモ

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0