Task 1 - simple validation rules

This commit is contained in:
PovilasKorop
2021-11-29 12:39:04 +02:00
parent 7f7f66dfea
commit 4b02ab4815
7 changed files with 113 additions and 70 deletions
+26
View File
@@ -0,0 +1,26 @@
<?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);
}
}