MOON
Server: Apache
System: Linux e2e-78-16.ssdcloudindia.net 3.10.0-1160.45.1.el7.x86_64 #1 SMP Wed Oct 13 17:20:51 UTC 2021 x86_64
User: imensosw (1005)
PHP: 8.0.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/imensosw/.trash/tests.1/Unit/Translator/UserContractTest.php
<?php

namespace Tests\Unit\Translator;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;

use Illuminate\Foundation\Testing\WithoutMiddleware;
use App\Models\UserContract;
use App\User;
use App\Models\UserSkillPair;
use App\Models\TranslatorFlag;
use App\Models\TranslatorType;
use Illuminate\Http\UploadedFile;
use App\Models\TranslatorStatus;

class UserContractTest extends TestCase
{
    protected $users, $clientData, $user_skill_pair, $translator_flag, $translator_type, $image, $translator_status;
    protected function setUp(): void 
    {
        parent::setUp();
        // $this->user_skill_pair = UserSkillPair::inRandomOrder()->first();
        $this->translator_flag = TranslatorFlag::inRandomOrder()->first();
        $this->translator_type = TranslatorType::inRandomOrder()->first();
        $this->image = 'balloons.pdf';
        $this->translator_status = TranslatorStatus::where('id',2)->first();

    }

    public function test_to_accept_contract()
    {
        $user = factory(User::class)->create();
        $profile =  factory(\App\Models\Profile::class)->create(['user_id'=>$user->id]);
        $from_language = factory(\App\Models\Language::class)->create();
        $to_language = factory(\App\Models\Language::class)->create();

        $translator_contract = factory(UserContract::class)->create([
            'user_id'=>$user->id,
            'from_language_id'=> $from_language->id,
            'to_language_id'  => $to_language->id,
            'status_id' => 1,
            'rating' => 4,
            'translator_flag_id' => $this->translator_flag->id,
            'translator_type_id' => $this->translator_type->id,
            'fixed_income' => 100,
            'proofreading_status_id' => 0,
            'translation_words' => null,
            'proofreading_words' => null,
            'translation_price' => 1.0,
            'proofreading_price' => 1.0,
        ]);


        $this->withoutMiddleware();
        $this->withoutExceptionHandling();

        $contract_file=UploadedFile::fake()->create($this->image);
        $this->actingAs($user)->json('GET','/profile');
    
        $data = [
            'user_id' =>$user->id,
            'from_language_id' => $from_language->id,
            'to_language_id'  => $to_language->id,
            'status_id' => 1,
            'rating' => 4,
            'translator_flag_id' => $this->translator_flag->id,
            'translator_type_id' => $this->translator_type->id,
            'fixed_income' => 100,
            'proofreading_status_id' => 0,
            'translation_words' => null,
            'proofreading_words' => null,
            'translation_price' => 1.0,
            'proofreading_price' => 1.0,
            'contract_file' => $contract_file,
            'contract_sent_date' => date("Y-m-d"),
            'contract_accept_date' => date("Y-m-d"),
            // 'translator_status_id' => $this->translator_status->id,
        ];


        $response = $this->json('POST', 'api/acceptContract', $data, 
            [
                'Accept' => 'application/json', 
                'HTTP_Authorization' => 'Bearer' . $user->remember_token
            ])
            ->assertStatus(200);
        $response->assertOk();

        UserContract::where('user_id',$user->id)->delete();
        \App\Models\Language::where('id', $from_language->id)->delete();
        \App\Models\Language::where('id', $to_language->id)->delete();
        \App\Models\Profile::where('user_id', $user->id)->delete();
        User::where('id',$user->id)->delete();
    }


    public function tearDown(): void
    {
        $maxId = \DB::table('user_contracts')->max('id');
        \DB::statement('ALTER TABLE user_contracts AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('languages')->max('id');
        \DB::statement('ALTER TABLE languages AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        
        $maxId = \DB::table('profiles')->max('id');
        \DB::statement('ALTER TABLE profiles AUTO_INCREMENT=' . intval($maxId + 1) . ';');

        $maxId = \DB::table('users')->max('id');
        \DB::statement('ALTER TABLE users AUTO_INCREMENT=' . intval($maxId + 1) . ';');
        parent::tearDown();
    }
}