Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '#5' of github.com:takuma348/Portfilio-PHP into feature/…
…AuthApi
- Loading branch information
Showing
9 changed files
with
139 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\User; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class LoginApiTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// テストユーザー作成 | ||
$this->user = factory(User::class)->create(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_登録済みのユーザーを認証して返却する() | ||
{ | ||
$response = $this->json('POST', route('login'), [ | ||
'email' => $this->user->email, | ||
'password' => 'secret', | ||
]); | ||
|
||
$response | ||
->assertStatus(200) | ||
->assertJson(['name' => $this->user->name]); | ||
|
||
$this->assertAuthenticatedAs($this->user); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\User; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class LogoutApiTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
// テストユーザー作成 | ||
$this->user = factory(User::class)->create(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_認証済みのユーザーをログアウトさせる() | ||
{ | ||
$response = $this->actingAs($this->user) | ||
->json('POST', route('logout')); | ||
|
||
$response->assertStatus(200); | ||
$this->assertGuest(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\User; | ||
use Tests\TestCase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
|
||
class RegisterApiTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function should_新しいユーザーを作成して返却する() | ||
{ | ||
$data = [ | ||
'name' => 'vuesplash user', | ||
'email' => 'dummy@email.com', | ||
'password' => 'test1234', | ||
'password_confirmation' => 'test1234', | ||
]; | ||
|
||
$response = $this->json('POST', route('register'), $data); | ||
|
||
$user = User::first(); | ||
$this->assertEquals($data['name'], $user->name); | ||
|
||
$response | ||
->assertStatus(201) | ||
->assertJson(['name' => $user->name]); | ||
} | ||
} |