Skip to content

Commit d72c076

Browse files
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.
1 parent 1e09e0b commit d72c076

9 files changed

Lines changed: 97 additions & 2 deletions

File tree

.env.testing

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
APP_NAME="Trypost.it"
2+
APP_ENV=testing
3+
APP_KEY=base64:oWfTqkX5cJwaVV7c8/z9xjC4XLGzbsKmjSgZiHtvxlk=
4+
APP_DEBUG=true
5+
APP_URL=https://trypost.test
6+
7+
DB_CONNECTION=pgsql
8+
DB_HOST=127.0.0.1
9+
DB_PORT=5432
10+
DB_DATABASE=trypost_test
11+
DB_USERNAME=root
12+
DB_PASSWORD=
13+
14+
# Test credentials for social platforms
15+
LINKEDIN_CLIENT_ID=test-linkedin-client-id
16+
LINKEDIN_CLIENT_SECRET=test-linkedin-client-secret
17+
18+
X_CLIENT_ID=test-x-client-id
19+
X_CLIENT_SECRET=test-x-client-secret
20+
21+
TIKTOK_CLIENT_ID=test-tiktok-client-id
22+
TIKTOK_CLIENT_SECRET=test-tiktok-client-secret
23+
24+
FACEBOOK_CLIENT_ID=test-facebook-client-id
25+
FACEBOOK_CLIENT_SECRET=test-facebook-client-secret
26+
27+
INSTAGRAM_CLIENT_ID=test-instagram-client-id
28+
INSTAGRAM_CLIENT_SECRET=test-instagram-client-secret
29+
30+
THREADS_CLIENT_ID=test-threads-client-id
31+
THREADS_CLIENT_SECRET=test-threads-client-secret
32+
33+
GOOGLE_CLIENT_ID=test-google-client-id
34+
GOOGLE_CLIENT_SECRET=test-google-client-secret
35+
36+
PINTEREST_CLIENT_ID=test-pinterest-client-id
37+
PINTEREST_CLIENT_SECRET=test-pinterest-client-secret
38+
39+
UNSPLASH_ACCESS_KEY=test-unsplash-access-key
40+
UNSPLASH_SECRET_KEY=test-unsplash-secret-key

app/Models/Language.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace App\Models;
44

55
use Illuminate\Database\Eloquent\Concerns\HasUuids;
6+
use Illuminate\Database\Eloquent\Factories\HasFactory;
67
use Illuminate\Database\Eloquent\Model;
78
use Illuminate\Database\Eloquent\Relations\HasMany;
89

910
class Language extends Model
1011
{
11-
use HasUuids;
12+
use HasFactory, HasUuids;
1213

1314
protected $fillable = [
1415
'name',
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
7+
/**
8+
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Language>
9+
*/
10+
class LanguageFactory extends Factory
11+
{
12+
/**
13+
* Define the model's default state.
14+
*
15+
* @return array<string, mixed>
16+
*/
17+
public function definition(): array
18+
{
19+
return [
20+
'name' => 'English',
21+
'code' => 'en-US',
22+
];
23+
}
24+
}

database/factories/UserFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Database\Factories;
44

5+
use App\Models\Language;
56
use Illuminate\Database\Eloquent\Factories\Factory;
67
use Illuminate\Support\Facades\Hash;
78
use Illuminate\Support\Str;
@@ -29,6 +30,7 @@ public function definition(): array
2930
'email_verified_at' => now(),
3031
'password' => static::$password ??= Hash::make('password'),
3132
'remember_token' => Str::random(10),
33+
'language_id' => Language::factory(),
3234
'two_factor_secret' => null,
3335
'two_factor_recovery_codes' => null,
3436
'two_factor_confirmed_at' => null,

database/migrations/0001_01_01_000000_create_users_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function up(): void
1414
Schema::create('languages', function (Blueprint $table) {
1515
$table->uuid('id')->primary();
1616
$table->string('name');
17-
$table->string('code')->unique();
17+
$table->string('code');
1818
$table->timestamps();
1919
});
2020

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<env name="QUEUE_CONNECTION" value="sync"/>
2929
<env name="SESSION_DRIVER" value="array"/>
3030
<env name="PULSE_ENABLED" value="false"/>
31+
<env name="FILESYSTEM_DISK" value="local"/>
3132
<env name="TELESCOPE_ENABLED" value="false"/>
3233
<env name="NIGHTWATCH_ENABLED" value="false"/>
3334
</php>

tests/CreatesApplication.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests;
6+
7+
use Illuminate\Contracts\Console\Kernel;
8+
use Illuminate\Foundation\Application;
9+
10+
trait CreatesApplication
11+
{
12+
/**
13+
* Creates the application.
14+
*/
15+
public function createApplication(): Application
16+
{
17+
$app = require __DIR__.'/../bootstrap/app.php';
18+
19+
$app->make(Kernel::class)->bootstrap();
20+
21+
return $app;
22+
}
23+
}

tests/Feature/Settings/ProfileUpdateTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
->patch(route('profile.update'), [
2121
'name' => 'Test User',
2222
'email' => '[email protected]',
23+
'language_id' => $user->language_id,
2324
]);
2425

2526
$response
@@ -41,6 +42,7 @@
4142
->patch(route('profile.update'), [
4243
'name' => 'Test User',
4344
'email' => $user->email,
45+
'language_id' => $user->language_id,
4446
]);
4547

4648
$response

tests/TestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
abstract class TestCase extends BaseTestCase
1010
{
11+
use CreatesApplication;
12+
1113
/**
1214
* Indicates whether the default seeder should run before each test.
1315
*

0 commit comments

Comments
 (0)