mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Update to laravel 5.4 style tests
This commit is contained in:
parent
229f718754
commit
a9d5b6ef92
22
tests/CreatesApplication.php
Normal file
22
tests/CreatesApplication.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Console\Kernel;
|
||||||
|
|
||||||
|
trait CreatesApplication
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Creates the application.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\Foundation\Application
|
||||||
|
*/
|
||||||
|
public function createApplication()
|
||||||
|
{
|
||||||
|
$app = require __DIR__.'/../bootstrap/app.php';
|
||||||
|
|
||||||
|
$app->make(Kernel::class)->bootstrap();
|
||||||
|
|
||||||
|
return $app;
|
||||||
|
}
|
||||||
|
}
|
23
tests/Feature/ExampleTest.php
Normal file
23
tests/Feature/ExampleTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class ExampleTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A basic test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBasicTest()
|
||||||
|
{
|
||||||
|
$response = $this->get('/');
|
||||||
|
|
||||||
|
$response->assertStatus(200);
|
||||||
|
}
|
||||||
|
}
|
@ -1,153 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* TestCase.php
|
|
||||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
||||||
*
|
|
||||||
* This software may be modified and distributed under the terms of the
|
|
||||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
||||||
*
|
|
||||||
* See the LICENSE file for details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Carbon\Carbon;
|
namespace Tests;
|
||||||
use FireflyIII\Models\Preference;
|
|
||||||
use FireflyIII\User;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TestCase
|
* Class TestCase
|
||||||
|
*
|
||||||
|
* @package Tests
|
||||||
*/
|
*/
|
||||||
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
/**
|
use CreatesApplication;
|
||||||
* The base URL to use while testing the application.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $baseUrl = 'http://localhost';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param User $user
|
|
||||||
* @param string $range
|
|
||||||
*/
|
|
||||||
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?
|
|
||||||
|
|
||||||
}
|
|
||||||
if ($range === 'custom') {
|
|
||||||
$this->session(
|
|
||||||
[
|
|
||||||
'start' => Carbon::now()->subDays(20),
|
|
||||||
'end' => Carbon::now(),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates the application.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Foundation\Application
|
|
||||||
*/
|
|
||||||
public function createApplication()
|
|
||||||
{
|
|
||||||
$app = require __DIR__ . '/../bootstrap/app.php';
|
|
||||||
|
|
||||||
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
|
|
||||||
|
|
||||||
return $app;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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'],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return User
|
|
||||||
*/
|
|
||||||
public function emptyUser()
|
|
||||||
{
|
|
||||||
$user = User::find(2);
|
|
||||||
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function naughtyStringProvider()
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* If on Travis, return very small set.
|
|
||||||
*/
|
|
||||||
if (getenv('TRAVIS') == 'true') {
|
|
||||||
return [['Default value']];
|
|
||||||
|
|
||||||
}
|
|
||||||
$path = realpath(__DIR__ . '/../resources/tests/blns.base64.json');
|
|
||||||
$content = file_get_contents($path);
|
|
||||||
$array = json_decode($content);
|
|
||||||
$return = [];
|
|
||||||
foreach ($array as $entry) {
|
|
||||||
$return[] = [base64_decode($entry)];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets up the fixture, for example, opens a network connection.
|
|
||||||
* This method is called before a test is executed.
|
|
||||||
*/
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @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;
|
|
||||||
}
|
|
||||||
}
|
}
|
20
tests/Unit/ExampleTest.php
Normal file
20
tests/Unit/ExampleTest.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Unit;
|
||||||
|
|
||||||
|
use Tests\TestCase;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
||||||
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
class ExampleTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* A basic test example.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testBasicTest()
|
||||||
|
{
|
||||||
|
$this->assertTrue(true);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user