File manager - Edit - /var/www/html/ciosp/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'), [ 'cpf' => '67108857049', 'password' => 'angra123' ]); $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')); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('users'); } public function test_store() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'cpf' => '67108857049', 'password' => 'angra123' ]); $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(), 'cpf' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); $response->assertSee('user'); } public function test_show() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'cpf' => '67108857049', 'password' => 'angra123' ]); $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(), 'cpf' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); $response->assertSee('user'); // showing user $user = $response['user']; $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->get(route('user.show', $user['id'])); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('user'); } public function test_update() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'cpf' => '67108857049', 'password' => 'angra123' ]); $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(), 'cpf' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); $response->assertSee('user'); // updating user $user = $response['user']; $response = $this->withHeaders([ 'Accept' => 'application/json', 'Authorization' => 'Bearer ' . $accessToken ])->put(route('user.update', $user['id']), [ 'name' => fake()->name(), 'email' => fake()->unique()->email(), 'cpf' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_OK); $response->assertSee('user'); } public function test_destroy() { // logging in $response = $this->withHeaders([ 'Accept' => 'application/json', ])->post(route('auth.login'), [ 'cpf' => '67108857049', 'password' => 'angra123' ]); $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(), 'cpf' => Str::random(11), 'registration' => Str::random(10), 'password' => Str::random(6), ]); $response->assertStatus(JsonResponse::HTTP_CREATED); $response->assertSee('user'); // deleting user $user = $response['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.01 |
proxy
|
phpinfo
|
Settings