<?php

namespace Tests\Feature;

use Illuminate\Support\Facades\Validator;
use Tests\TestCase;

class ValidationMessagesTest extends TestCase
{
    public function test_messages_localized_in_german(): void
    {
        app()->setLocale('de');
        $v = Validator::make(
            ['name' => '', 'email' => 'nope', 'sshPort' => 'x'],
            ['name' => 'required', 'email' => 'email', 'sshPort' => 'integer'],
        );

        $this->assertStringContainsString('muss ausgefüllt werden', $v->errors()->first('name'));
        $this->assertStringContainsString('gültige E-Mail-Adresse', $v->errors()->first('email'));
        // localized attribute label from the `attributes` array
        $this->assertStringContainsString('SSH-Port', $v->errors()->first('sshPort'));
    }

    public function test_messages_localized_in_english(): void
    {
        app()->setLocale('en');
        $v = Validator::make(['name' => ''], ['name' => 'required']);

        $this->assertStringContainsString('is required', $v->errors()->first('name'));
    }
}
