File manager - Edit - /var/www/html/spdc/api/tests/Feature/UserTest.php
Back
<?php namespace Tests\Feature; // use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; use Illuminate\Support\Str; use Illuminate\Http\JsonResponse; use Illuminate\Foundation\Testing\DatabaseTransactions; class UserTest extends TestCase { /** * A basic test example. * * @return void */ public function test_index() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); // index $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $response['access_token'] ])->get(route('user.index')); dd($response->json()); $response->assertStatus(JsonResponse::HTTP_OK); } public function test_index_with_filters() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); // index $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $response['access_token'] ])->get(route('user.index', [ 'registration' => '123456', 'name' => 'Prof.' ])); dd($response->json()); $response->assertStatus(JsonResponse::HTTP_OK); } public function test_store() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); // storing user $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $response['access_token'] ])->post(route('user.store'), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'username' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); } public function test_show() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); $accessToken = $response['access_token']; // storing user $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->post(route('user.store'), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'username' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); // showing user $user = $response['data']['user']; $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->get(route('user.show', $user['id'])); $response->assertStatus(JsonResponse::HTTP_OK); } public function test_update() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); $accessToken = $response['access_token']; // storing user $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->post(route('user.store'), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'username' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); // updating user $user = $response['data']['user']; $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->put(route('user.update', $user['id']), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'username' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_OK); } public function test_destroy() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'username' => env('USERNAME'), 'password' => env('PASSWORD') ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('access_token'); $accessToken = $response['access_token']; // storing user $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->post(route('user.store'), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'username' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); // deleting user $user = $response['data']['user']; $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->delete(route('user.destroy', $user['id'])); $response->assertStatus(JsonResponse::HTTP_NO_CONTENT); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.14 |
proxy
|
phpinfo
|
Settings