Files
firefly-iii/tests/TestCase.php

122 lines
2.9 KiB
PHP
Raw Normal View History

2015-07-02 09:44:56 +02:00
<?php
2017-08-11 05:36:05 +02:00
/**
* TestCase.php
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2017-12-17 14:42:21 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2017-08-11 05:36:05 +02:00
*/
2017-08-18 21:08:51 +02:00
declare(strict_types=1);
2017-02-05 15:42:00 +01:00
namespace Tests;
2017-02-12 12:21:44 +01:00
use Carbon\Carbon;
use FireflyIII\Models\Preference;
use FireflyIII\User;
2017-02-05 15:42:00 +01:00
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Log;
use Mockery;
2017-02-12 12:21:44 +01:00
2016-10-09 07:58:27 +02:00
/**
* Class TestCase
2017-02-05 15:42:00 +01:00
*
2017-08-12 10:27:45 +02:00
* @SuppressWarnings(PHPMD.NumberOfChildren)
2016-10-09 07:58:27 +02:00
*/
2017-02-05 15:42:00 +01:00
abstract class TestCase extends BaseTestCase
2015-07-02 09:44:56 +02:00
{
2017-02-05 15:42:00 +01:00
use CreatesApplication;
/**
* @param User $user
* @param string $range
2017-12-17 14:30:53 +01:00
*
* @throws \Exception
*/
public function changeDateRange(User $user, $range)
{
$valid = ['1D', '1W', '1M', '3M', '6M', '1Y', 'custom'];
if (in_array($range, $valid)) {
Preference::where('user_id', $user->id)->where('name', 'viewRange')->delete();
Preference::create(
[
'user_id' => $user->id,
'name' => 'viewRange',
'data' => $range,
]
);
// set period to match?
}
2017-11-22 21:12:27 +01:00
if ('custom' === $range) {
$this->session(
[
'start' => Carbon::now()->subDays(20),
'end' => Carbon::now(),
]
);
}
}
/**
* @return array
*/
public function dateRangeProvider()
{
return [
'one day' => ['1D'],
'one week' => ['1W'],
'one month' => ['1M'],
'three months' => ['3M'],
'six months' => ['6M'],
'one year' => ['1Y'],
'custom range' => ['custom'],
];
}
2017-02-12 12:21:44 +01:00
/**
* @return User
*/
public function emptyUser()
{
$user = User::find(2);
return $user;
}
/**
* @return User
*/
public function user()
{
$user = User::find(1);
return $user;
}
/**
* @param string $class
*
* @return \Mockery\MockInterface
*/
protected function mock($class)
{
Log::debug(sprintf('Will now mock %s', $class));
$object = Mockery::mock($class);
$this->app->instance($class, $object);
return $object;
}
}