Advertisement
Guest User

app/tests/TestCase.php

a guest
Nov 20th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. class TestCase extends Illuminate\Foundation\Testing\TestCase {
  4.  
  5.     /**
  6.      *
  7.      */
  8.     public function setUp()
  9.     {
  10.         parent::setUp();
  11.         $this->prepareForTests();
  12.     }
  13.    
  14.     /**
  15.      * Creates the application.
  16.      *
  17.      * @return Symfony\Component\HttpKernel\HttpKernelInterface
  18.      */
  19.     public function createApplication()
  20.     {
  21.         $unitTesting = true;
  22.  
  23.         $testEnvironment = 'testing';
  24.  
  25.         return require __DIR__.'/../../bootstrap/start.php';
  26.     }
  27.    
  28.     /**
  29.      * Migrate the database
  30.      */
  31.     private function prepareForTests()
  32.     {
  33.         Artisan::call('migrate');
  34.     }
  35.    
  36.    
  37.     /**
  38.      * Username is required
  39.      */
  40.     public function testUsernameIsRequired()
  41.     {
  42.         // Create a new User
  43.         $user = new User;
  44.         $user->user_email               = 'test@test.se';
  45.         $user->password                 = 'password';
  46.         $user->password_confirmation    = 'password';
  47.        
  48.         // User should not save
  49.         $this->assertFalse($user->save());
  50.        
  51.         // Save the errors
  52.         $errors = $user->errors()->all();
  53.        
  54.         // There should be 1 error
  55.         $this->assertCount(1, $errors);
  56.        
  57.         // The username error should be set
  58.         $this->assertEquals($errors[0], 'The username field is required');
  59.     }
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement