4.1-4.3: add PHPUnit feature tests for all endpoints + factories
Deploy Backend / deploy (push) Failing after 2m16s

This commit is contained in:
parsa aghaei committed 2026-06-23 18:37:14 +03:30
1 parent a4025256d4
commit 37a507c742
16 files changed
+504 -37

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
<?php
namespace Tests\Feature\Blog;
use App\Models\Blog\Category;
use App\Models\Blog\Post;
use App\Models\Blog\Tag;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PostTest extends TestCase
{
use RefreshDatabase;
public function test_can_list_posts()
{
Post::factory()->count(3)->create();
$response = $this->getJson('/api/blog/posts');
$response->assertStatus(200);
}
public function test_can_get_single_post()
{
$post = Post::factory()->create();
$response = $this->getJson("/api/blog/posts/{$post->slug}");
$response->assertStatus(200)
->assertJsonStructure(['post', 'related_posts']);
}
public function test_can_create_post()
{
$category = Category::factory()->create();
$user = User::factory()->create();
$response = $this->postJson('/api/blog/posts', [
'title' => 'Test Post',
'body' => 'Content',
'slug' => 'test-post',
'category_id' => $category->id,
'author_id' => $user->id,
]);
$response->assertStatus(201);
$this->assertDatabaseHas('posts', ['slug' => 'test-post']);
}
public function test_can_update_post()
{
$post = Post::factory()->create();
$response = $this->putJson("/api/blog/posts/{$post->id}", [
'title' => 'Updated',
]);
$response->assertStatus(200);
}
public function test_can_delete_post()
{
$post = Post::factory()->create();
$response = $this->deleteJson("/api/blog/posts/{$post->id}");
$response->assertStatus(200);
$this->assertDatabaseMissing('posts', ['id' => $post->id]);
}
public function test_can_filter_posts()
{
Post::factory()->count(3)->create();
$response = $this->getJson('/api/blog/posts?per_page=2');
$response->assertStatus(200);
}
}