Last active
August 29, 2015 14:26
-
-
Save jaceju/bf5de573f1d1daf251b6 to your computer and use it in GitHub Desktop.
Auth Unit Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Foundation\Testing\DatabaseMigrations; | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
use Illuminate\Support\Facades\Auth; | |
class ExampleTest extends TestCase | |
{ | |
/** | |
* DatabaseTransactions :在測試其間對資料庫的所有操作會在測試完成後被滾回 | |
* DatabaseMigrations: 建立需要的資料表 | |
*/ | |
use DatabaseMigrations, DatabaseTransactions; | |
public function testSignInWithRandomUser() | |
{ | |
// 在 users 資料表中建立一個使用者並回傳 User model | |
$user = factory(App\User::class)->create(); | |
// 假定該使用者已經登入 | |
$this->be($user); | |
// 驗證登入狀態 | |
$this->assertTrue(Auth::check()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment