First tests for User model.

This commit is contained in:
James Cole committed 2014-07-03 09:43:12 +02:00
1 parent 924ec29eaf
commit 3d1bc5891f
4 files changed
+82 -3

No files matched your search

@@ -0,0 +1,23 @@
<?php
class HomeControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function testIndex()
{
// mock:
View::shouldReceive('make')->with('index');
Auth::shouldReceive('check')->andReturn(true);
// call
$this->call('GET', '/');
// test
$this->assertResponseOk();
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php
class UserTest extends TestCase
{
/**
* Default preparation for each test
*/
public function setUp()
{
parent::setUp();
$this->prepareForTests();
}
/**
* Migrate the database
*/
private function prepareForTests()
{
Artisan::call('migrate');
}
/**
* Username is required
*/
public function testUsernameIsRequired()
{
// Create a new User
$user = new User;
$user->migrated = 0;
$user->password = Str::random(60);
// User should not save
$this->assertFalse($user->isValid());
// Save the errors
$errors = $user->validator->messages()->all();
// // There should be 1 error
$this->assertCount(1, $errors);
// // The username error should be set
$this->assertEquals($errors[0], "The email field is required.");
}
}