Ray Lee | 李宗叡
Learn or Die
Published in
3 min readDec 9, 2020

--

Photo by Antoine Dautry on Unsplash

# 前言

我喜歡使用 Laravel 開發的感覺, 除了開發快速, 程式碼簡潔且優雅之外, Laravel 框架本身也是一個很好的學習參照物。 本篇主要將官方文件重點整理成 Q&A 的形式呈現, 原子化的概念, 這方式並不適用於每個人, 但若對你有幫助, 我會很開心。

# 版本

Laravel 8.x

# 目錄

Laravel — 官方文件原子化翻譯 — 目錄

# Environment

Laravel Testing 中, 會使用 session 或 cache 嗎?

不會, 會使用 array driver 代替

Laravel Testing 中, 設定檔是哪一個?

phpunit.xml

Laravel Testing 中, 若要複寫 .env 的設定, 提供一些 env 專為了 testing 環境而使用, 可以怎麼做?

建立 .env.testing 檔案

# Creating & Running Tests

以下的 Laravel example code 的意思是?

  • Example:
<?php
php artisan make:test UserTest

php artisan make:test UserTest --unit
  • Answer:
<?php
// 建立 feature test, 通常用來測試整個 HTTP request
php artisan make:test UserTest

// 建立 unit test, 通常測試範圍為一個 method
php artisan make:test UserTest --unit

以下的 Laravel example code 的意思是?

  • Example:
<?php

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;

class ExampleTest extends TestCase
{
public function testBasicTest()
{
$this->assertTrue(true);
}
}
  • Answer: 建立一個 test 之後, 可以在裡面定義測試邏輯, 範例會 return true, 只是個範例

# Artisan Test Runner

以下的 Laravel example command 的意思是?

  • Example:
php artisan test --testsuite=Feature --stop-on-failure
  • Answer: 建立一個 test file, 指定類行為 feature, 並且失敗就停下

--

--

Ray Lee | 李宗叡
Learn or Die

It's Ray. I do both backend and frontend, but more focus on backend. I like coding, and would like to see the whole picture of a product.