Cachet/tests/AbstractTestCase.php

88 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/*
* This file is part of Cachet.
*
2015-07-06 17:37:01 +01:00
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Tests\Cachet;
2016-10-02 15:57:32 +03:00
use CachetHQ\Cachet\Models\User;
use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository;
use Illuminate\Foundation\Testing\TestCase;
2015-12-06 11:04:02 +00:00
/**
* This is the abstract test case class.
*
* @author Graham Campbell <graham@alt-three.com>
2018-06-25 22:13:53 +01:00
* @author James Brooks <james@alt-three.com>
2015-12-06 11:04:02 +00:00
*/
2015-06-01 22:25:34 +01:00
abstract class AbstractTestCase extends TestCase
{
2018-06-25 22:13:53 +01:00
use CreatesApplicationTrait;
2015-06-01 22:25:34 +01:00
2016-10-02 15:57:32 +03:00
/**
* Test actor.
*
2016-10-19 12:29:16 +01:00
* @var \CachetHQ\Cachet\Models\User
2016-10-02 15:57:32 +03:00
*/
protected $user;
/**
* Sign in an user if it's the case.
*
2017-02-06 20:20:55 +00:00
* @param \CachetHQ\Cachet\Models\User|null $user
2016-10-02 15:57:32 +03:00
*
2016-10-19 12:29:16 +01:00
* @return \CachetHQ\Tests\Cachet\AbstractTestCase
2016-10-02 15:57:32 +03:00
*/
protected function signIn(User $user = null)
{
$this->user = $user ?: $this->createUser();
$this->be($this->user);
return $this;
}
/**
* Create and return a new user.
*
* @param array $properties
*
2016-10-19 12:29:16 +01:00
* @return \CachetHQ\Cachet\Models\User
2016-10-02 15:57:32 +03:00
*/
protected function createUser($properties = [])
{
return factory(User::class)->create($properties);
}
/**
* Set up the needed configuration to be able to run the tests.
*
2016-10-19 12:29:16 +01:00
* @return \CachetHQ\Tests\Cachet\AbstractTestCase
2016-10-02 15:57:32 +03:00
*/
protected function setupConfig()
{
$env = $this->app->environment();
$repo = $this->app->make(Repository::class);
$cache = $this->app->make(Cache::class);
$loaded = $cache->load($env);
if ($loaded === false) {
$loaded = $repo->all();
$cache->store($env, $loaded);
}
$settings = array_merge($this->app->config->get('setting'), $loaded);
$this->app->config->set('setting', $settings);
return $this;
}
}