mirror of
https://github.com/10h30/Test-Laravel-Validation.git
synced 2026-06-05 15:07:56 +09:00
27 lines
784 B
PHP
27 lines
784 B
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class ValidationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_simple_validation_rules()
|
|
{
|
|
// Post without any title should fail because title is required
|
|
$response = $this->post('posts');
|
|
$response->assertSessionHasErrors('title')->assertStatus(302);
|
|
|
|
// Post with title should succeed
|
|
$response = $this->post('posts', ['title' => 'Some title']);
|
|
$response->assertStatus(200);
|
|
|
|
// Post with the same title should fail because it's not unique
|
|
$response = $this->post('posts', ['title' => 'Some title']);
|
|
$response->assertSessionHasErrors('title')->assertStatus(302);
|
|
}
|
|
}
|