<?php

/*
 * This file is part of ibrand/balace.
 *
 * (c) iBrand <https://www.ibrand.cc>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace iBrand\Component\User\Test;

use iBrand\Component\User\Models\User;
use iBrand\Component\User\Models\UserBind;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Orchestra\Testbench\TestCase;

/**
 * Class BaseTest.
 */
abstract class BaseTest extends TestCase
{
	use DatabaseMigrations;

	public $user;

	/**
	 * set up test.
	 */
	protected function setUp()
	{
		parent::setUp(); // TODO: Change the autogenerated stub

		$this->user = $this->app->make(\iBrand\Component\User\Repository\UserRepository::class);

		$this->seedUser();

		$this->seedUserBind();
	}

	/**
	 * @param \Illuminate\Foundation\Application $app
	 */
	protected function getEnvironmentSetUp($app)
	{
		// Setup default database to use sqlite :memory:
		$app['config']->set('database.default', 'testing');
		$app['config']->set('database.connections.testing', [
			'driver'   => 'sqlite',
			'database' => ':memory:',
		]);
		$app['config']->set('repository.cache.enabled', true);
	}

	/**
	 * @param $paths
	 */
	protected function loadMigrationsFrom($paths)
	{
		$this->artisan('migrate', ['--database' => 'testing']);
	}

	/**
	 * @param \Illuminate\Foundation\Application $app
	 *
	 * @return array
	 */
	protected function getPackageProviders($app)
	{
		return [
			\Orchestra\Database\ConsoleServiceProvider::class,
			\iBrand\Component\User\UserServiceProvider::class,
			\iBrand\Component\User\Test\UserTestServiceProvider::class,
		];
	}

	/**
	 * seed some balance.
	 */
	public function seedUser()
	{
		User::create([
			'name'               => 'tangqi',
			'nick_name'          => '承诺',
			'extend_id'          => 0,
			'email'              => '923332947@qq.com',
			'mobile'             => '18684738715',
			'password'           => '123456',
			'status'             => '1',
			'confirmation_code'  => '',
			'confirmed'          => 0,
			'sex'                => '男',
			'avatar'             => 'http://admin.dev.tnf.ibrand.cc/uploads/dRhYHqAhbb.jpg',
			'integral'           => '52672.5',
			'current_exp'        => '43795',
			'available_integral' => '8227.5',
			'discount'           => '',
			'city'               => '长沙市',
			'education'          => 'tangqi',
			'birthday'           => '1983-5-1',
			'qq'                 => '923332947',
			'card_limit'         => '2017-06-29',
			'remember_token'     => 'tangqi',
			'group_id'           => 'tangqi',
			'union_id'           => 'tangqi',
		]);
	}

	public function seedUserBind()
	{
		UserBind::create([
			'type'          => '',
			'open_id'       => '',
			'user_id'       => '',
			'nick_name'     => '',
			'name'          => '',
			'email'         => '',
			'avatar'        => '',
			'token'         => '',
			'refresh_token' => '',
			'expired_at'    => '',
			'app_id'        => '',
		]);
	}
}