Answer the question
In order to leave comments, you need to log in
How does the test syntax from Laravel - PHPUnit work?
Good afternoon :)
In general, I'm sitting here writing tests and noticed a strange difference in the syntax. Or am I missing something in the documentation again.
In short, there are such tests.
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ThreadsTest extends TestCase
{
use DatabaseMigrations;
public function testA_user_can_view_all_threads()
{
$thread = factory('App\Thread')->create();
$response = $this->get('/threads');
$response->assertSee($thread->title);
}
function testA_user_can_read_a_single_thread()
{
$thread = factory('App\Thread')->create();
$responce = $this->get('/threads/'. $thread->id);
$responce->assertSee($thread->title);
}
function testNew_test()
{
$thread = factory('App\Thread')->create();
$responce = $this->get('/thread');
$responce->assertStatus(200);
}
}
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.
.... 4 / 4 (100%)
Time: 1.81 seconds, Memory: 16.00MB
OK (4 tests, 4 assertions)
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ThreadsTest extends TestCase
{
use DatabaseMigrations;
public function a_user_can_view_all_threads()
{
$thread = factory('App\Thread')->create();
$response = $this->get('/threads');
$response->assertSee($thread->title);
}
function a_user_can_read_a_single_thread()
{
$thread = factory('App\Thread')->create();
$responce = $this->get('/threads/'. $thread->id);
$responce->assertSee($thread->title);
}
function new_test()
{
$thread = factory('App\Thread')->create();
$responce = $this->get('/threads');
$responce->assertStatus(200);
}
}
PHPUnit 5.7.20 by Sebastian Bergmann and contributors.
W. 2 / 2 (100%)
Time: 652 ms, Memory: 8.00MB
There was 1 warning:
1) Warning
No tests found in class "Tests\Feature\ThreadsTest".
WARNINGS!
Tests: 2, Assertions: 1, Warnings: 1.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question