Compare commits
4 Commits
8772331868
...
ae59f826e9
Author | SHA1 | Date | |
---|---|---|---|
ae59f826e9 | |||
b4c44f5a14 | |||
7797575fd3 | |||
1e3ef6a398 |
@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Symfony\Component\HttpFoundation\Exception\BadRequestException;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
@ -16,6 +18,15 @@ public function index()
|
|||||||
// GET /user/{id}
|
// GET /user/{id}
|
||||||
public function show(string $id)
|
public function show(string $id)
|
||||||
{
|
{
|
||||||
|
// FIXME: is there more shorter
|
||||||
|
// validation solution
|
||||||
|
$v = Validator::make(["id" => $id], [
|
||||||
|
"id" => 'integer'
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($v->fails())
|
||||||
|
throw new BadRequestException();
|
||||||
|
|
||||||
$user = User::query()->findOrFail($id);
|
$user = User::query()->findOrFail($id);
|
||||||
|
|
||||||
return response($user);
|
return response($user);
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class CommentaryTest extends TestCase
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class PostTest extends TestCase
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Tests\Feature;
|
|
||||||
|
|
||||||
use Tests\TestCase;
|
|
||||||
|
|
||||||
class TagTest extends TestCase
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
@ -3,12 +3,14 @@
|
|||||||
namespace Tests\Feature;
|
namespace Tests\Feature;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class UserTest extends TestCase
|
class UserTest extends TestCase
|
||||||
{
|
{
|
||||||
// FIXME: tests should be
|
// FIXME: tests should be
|
||||||
// grouped and be separated in several files
|
// grouped and be separated in several files
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
public function test_success_get_users(): void
|
public function test_success_get_users(): void
|
||||||
{
|
{
|
||||||
@ -34,6 +36,6 @@ public function test_fail_get_user_not_exists(): void
|
|||||||
// but in future updates id
|
// but in future updates id
|
||||||
// will be uuid, it is safer
|
// will be uuid, it is safer
|
||||||
$this->get('/user/sehtrgher')
|
$this->get('/user/sehtrgher')
|
||||||
->assertNotFound();
|
->assertBadRequest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
namespace Tests;
|
namespace Tests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
//
|
protected $seed = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user