<?php

use Faker\Factory as Faker;
use Faker\Generator as FakerGenerator;
use \Illuminate\Support\Facades\Artisan;

class TestCase extends Illuminate\Foundation\Testing\TestCase {

  /**
   * @var FakerGenerator
   */
  protected $__faker;
  private static $_db_init = false;

  public function setUp()
  {
    parent::setUp();

    $this->__faker = Faker::create('ru_RU');

    if(!self::$_db_init)
    {
      Artisan::call('db:seed', ['--class' => 'DatabaseTestingSeeder']);
      self::$_db_init = true;
    }

  }


	/**
	 * Creates the application.
	 *
	 * @return \Illuminate\Foundation\Application
	 */
	public function createApplication()
	{
		$app = require __DIR__.'/../bootstrap/app.php';

		$app->make('Illuminate\Contracts\Console\Kernel')->bootstrap();

		return $app;
	}

	protected function setAdmin()
	{
		$user = App\User::find(1);
		$this->be($user);

		return $user;
	}

  protected function setModerator()
	{
		$user = App\User::find(2);
		$this->be($user);

		return $user;
	}

  protected function setCompany()
  {
    $user = App\User::find(3);
    $this->be($user);

    return $user;
  }

  protected function setUser($uid=4)
	{
		$user = App\User::find($uid);
		$this->be($user);

		return $user;
	}

}
