From 982d0bbc9e313c0d7e9e94339c39103752587937 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Wed, 12 Sep 2018 16:44:31 -0300 Subject: [PATCH] Including first Laravel UnitText Experience These changes will stay here so I can use them as examples to come back later to include some real tests. --- database/factories/UserFactory.php | 9 +++++++++ phpunit.xml | 1 + tests/Feature/ExampleTest.php | 13 ++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index facf233..83bc1e8 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -21,3 +21,12 @@ $factory->define(App\User::class, function (Faker $faker) { 'remember_token' => str_random(10), ]; }); + +$factory->define(App\Product::class, function (Faker $faker) { + return [ + 'name' => $faker->sentence, + 'user_id' => function () { + return factory(App\User::class)->create()->id; + }, + ]; +}); \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml index 733dc0d..13a1423 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -29,5 +29,6 @@ + diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index f31e495..009e353 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -2,11 +2,14 @@ namespace Tests\Feature; +use \App\Product; use Tests\TestCase; use Illuminate\Foundation\Testing\RefreshDatabase; class ExampleTest extends TestCase { + use RefreshDatabase; + /** * A basic test example. * @@ -14,8 +17,16 @@ class ExampleTest extends TestCase */ public function testBasicTest() { - $response = $this->get('/'); + $response = $this->get('/'); $response->assertStatus(200); + + //Just to remember the assertSee + $this->get('/')->assertSee('Login'); + + //Learning how to make unit tests with Laravel + factory(Product::class)->create(); + $products = Product::all(); + $this->assertCount(1, $products); } }