feat: Establish a dedicated testing environment with .env.testing, CreatesApplication trait, and Language model factory, integrating language selection into user profile tests and adjusting the languages table migration.

This commit is contained in:
Paulo Castellano 2026-01-18 19:56:04 -03:00
parent 1e09e0b1b9
commit d72c076658
9 changed files with 97 additions and 2 deletions

40
.env.testing Normal file
View file

@ -0,0 +1,40 @@
APP_NAME="Trypost.it"
APP_ENV=testing
APP_KEY=base64:oWfTqkX5cJwaVV7c8/z9xjC4XLGzbsKmjSgZiHtvxlk=
APP_DEBUG=true
APP_URL=https://trypost.test
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=trypost_test
DB_USERNAME=root
DB_PASSWORD=
# Test credentials for social platforms
LINKEDIN_CLIENT_ID=test-linkedin-client-id
LINKEDIN_CLIENT_SECRET=test-linkedin-client-secret
X_CLIENT_ID=test-x-client-id
X_CLIENT_SECRET=test-x-client-secret
TIKTOK_CLIENT_ID=test-tiktok-client-id
TIKTOK_CLIENT_SECRET=test-tiktok-client-secret
FACEBOOK_CLIENT_ID=test-facebook-client-id
FACEBOOK_CLIENT_SECRET=test-facebook-client-secret
INSTAGRAM_CLIENT_ID=test-instagram-client-id
INSTAGRAM_CLIENT_SECRET=test-instagram-client-secret
THREADS_CLIENT_ID=test-threads-client-id
THREADS_CLIENT_SECRET=test-threads-client-secret
GOOGLE_CLIENT_ID=test-google-client-id
GOOGLE_CLIENT_SECRET=test-google-client-secret
PINTEREST_CLIENT_ID=test-pinterest-client-id
PINTEREST_CLIENT_SECRET=test-pinterest-client-secret
UNSPLASH_ACCESS_KEY=test-unsplash-access-key
UNSPLASH_SECRET_KEY=test-unsplash-secret-key

View file

@ -3,12 +3,13 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Language extends Model
{
use HasUuids;
use HasFactory, HasUuids;
protected $fillable = [
'name',

View file

@ -0,0 +1,24 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Language>
*/
class LanguageFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => 'English',
'code' => 'en-US',
];
}
}

View file

@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Language;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
@ -29,6 +30,7 @@ public function definition(): array
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'language_id' => Language::factory(),
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
'two_factor_confirmed_at' => null,

View file

@ -14,7 +14,7 @@ public function up(): void
Schema::create('languages', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->string('code')->unique();
$table->string('code');
$table->timestamps();
});

View file

@ -28,6 +28,7 @@
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="PULSE_ENABLED" value="false"/>
<env name="FILESYSTEM_DISK" value="local"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="NIGHTWATCH_ENABLED" value="false"/>
</php>

View file

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Application;
trait CreatesApplication
{
/**
* Creates the application.
*/
public function createApplication(): Application
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
return $app;
}
}

View file

@ -20,6 +20,7 @@
->patch(route('profile.update'), [
'name' => 'Test User',
'email' => 'test@example.com',
'language_id' => $user->language_id,
]);
$response
@ -41,6 +42,7 @@
->patch(route('profile.update'), [
'name' => 'Test User',
'email' => $user->email,
'language_id' => $user->language_id,
]);
$response

View file

@ -8,6 +8,8 @@
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
/**
* Indicates whether the default seeder should run before each test.
*