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); } }