File manager - Edit - /var/www/html/gop/api/tests/Feature/NotaFiscalTest.php
Back
<?php namespace Tests\Feature; use App\Models\Arquivo; use App\Models\Empenho; use App\Models\Image; use App\Models\NotaFiscal; use App\Models\Obra; use Illuminate\Http\JsonResponse; use Illuminate\Http\UploadedFile; use Tests\BaseTest; class NotaFiscalTest extends BaseTest { public function test_index() { NotaFiscal::factory(10)->create(); $this->authRequest( 'get', route('nota-fiscal.index'), ); } public function test_store_and_update() { $obra = Obra::factory()->create(); [$empenho1, $empenho2] = Empenho::factory(2)->create(['obra_id' => $obra->id, 'valor' => $obra->valor_ajustado / 2]); $notaFiscalArray = NotaFiscal::factory()->make()->toArray(); $request = [ 'numero' => (string) $notaFiscalArray['numero'], 'data' => $notaFiscalArray['data'], 'valor' => $empenho1->valor / 2 + $empenho2->valor / 2, 'obra_id' => $obra->id, 'empenhos' => [ [ 'id' => $empenho1->id, 'valor_empenhado' => $empenho1->valor / 2, ], [ 'id' => $empenho2->id, 'valor_empenhado' => $empenho2->valor / 2, ], ], ]; $response = $this->authRequest( 'post', route('nota-fiscal.store'), JsonResponse::HTTP_CREATED, $request, ); $response->assertSee($notaFiscalArray['numero']); $notaFiscalArray = NotaFiscal::factory()->make()->toArray(); $request = [ 'numero' => (string) $notaFiscalArray['numero'], 'data' => $notaFiscalArray['data'], ]; $this->authRequest( 'put', route('nota-fiscal.update', $response['id']), JsonResponse::HTTP_OK, $request, ); } public function test_show() { $notaFiscal = NotaFiscal::factory()->create(); $arquivos = Arquivo::factory(3)->create([ 'arquivable_id' => $notaFiscal->id, 'arquivable_type' => NotaFiscal::class, ]); $images = Image::factory(3)->create([ 'imageable_id' => $notaFiscal->id, 'imageable_type' => NotaFiscal::class, ]); $this->authRequest( 'get', route('nota-fiscal.show', $notaFiscal->id), ); foreach ($arquivos as $arquivo) { $this->removeTestFiles($arquivo->path); } foreach ($images as $image) { $this->removeTestFiles($image->path); } } public function test_destroy() { $notaFiscal = NotaFiscal::factory()->create(); $this->authRequest( 'delete', route('nota-fiscal.destroy', $notaFiscal->id), JsonResponse::HTTP_NO_CONTENT, ); } public function test_PrivateFields() { $model = NotaFiscal::factory()->create(); $request = [ 'fields' => [ 'id', ], ]; $this->authRequest( 'post', route('nota-fiscal.setPrivateFields', $model->id), JsonResponse::HTTP_OK, $request, ); $this->authRequest( 'get', route('nota-fiscal.showPrivateFields', $model->id), ); } public function test_storeImage_and_showImage() { $modelo = NotaFiscal::factory()->create(); $image = new UploadedFile( storage_path('test/assinatura.png'), 'assinatura.png', 'image/png', null, true ); $request = [ 'image' => $image, ]; $response = $this->authRequest( 'post', route('nota-fiscal.storeImage', $modelo->id), JsonResponse::HTTP_CREATED, $request, ); $this->authRequest( 'get', route('nota-fiscal.showModelImages', $modelo->id), JsonResponse::HTTP_OK, $request, ); $this->removeTestFiles($response->json('path')); } public function test_storeFile_and_showFile() { $modelo = NotaFiscal::factory()->create(); $file = new UploadedFile( storage_path('test/pdf-test.pdf'), 'pdf-test.pdf', 'file/pdf', null, true ); $request = [ 'arquivo' => $file, ]; $response = $this->authRequest( 'post', route('nota-fiscal.storeFile', $modelo->id), JsonResponse::HTTP_CREATED, $request, ); $this->authRequest( 'get', route('nota-fiscal.showModelFiles', $modelo->id), JsonResponse::HTTP_OK, $request, ); $this->removeTestFiles($response->json('path')); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.28 | Generation time: 0.01 |
proxy
|
phpinfo
|
Settings