make sure randomly selected journals match prerequisites.

This commit is contained in:
James Cole 2018-03-02 17:07:32 +01:00
parent 139c2284b8
commit 36113f84be
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
80 changed files with 728 additions and 281 deletions

View File

@ -24,8 +24,9 @@ declare(strict_types=1);
namespace Tests\Api\V1\Controllers;
use Laravel\Passport\Passport;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class AboutControllerTest
*/

View File

@ -28,8 +28,8 @@ use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Laravel\Passport\Passport;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class AccountControllerTest

View File

@ -26,6 +26,7 @@ namespace Tests\Api\V1\Controllers;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\NegativeAmountFilter;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -1349,7 +1350,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('setJournals')->andReturnSelf()->once();
$collector->shouldReceive('addFilter')->andReturnSelf()->once();
$collector->shouldReceive('addFilter')->withArgs([NegativeAmountFilter::class])->andReturnSelf()->once();
$collector->shouldReceive('getJournals')->andReturn($transactions);
// test API
@ -1360,6 +1361,7 @@ class TransactionControllerTest extends TestCase
'data' => [
'attributes' => [
'description' => $journal->description,
'type' => 'Deposit',
],
'links' => [
0 => [],
@ -2172,8 +2174,8 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$source]), new Collection([$dest]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$piggy = $this->user()->piggyBanks()->first();
$data = [
$piggy = $this->user()->piggyBanks()->first();
$data = [
'description' => 'Some transfer #' . rand(1, 1000),
'date' => '2018-01-01',
'type' => 'transfer',
@ -2209,7 +2211,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
$data = [
'description' => 'Some transaction #' . rand(1, 1000),
'date' => '2018-01-01',
'type' => 'withdrawal',
@ -2247,7 +2249,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
$data = [
'description' => 'Some transaction #' . rand(1, 1000),
'date' => '2018-01-01',
'type' => 'withdrawal',
@ -2285,7 +2287,7 @@ class TransactionControllerTest extends TestCase
*/
public function testSuccessStoreTags()
{
$tags = [
$tags = [
'TagOne' . rand(1, 1000),
'TagTwoBlarg' . rand(1, 1000),
'SomeThreeTag' . rand(1, 1000),
@ -2299,7 +2301,7 @@ class TransactionControllerTest extends TestCase
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$journalRepos->shouldReceive('store')->andReturn($journal)->once();
$data = [
$data = [
'description' => 'Some transaction #' . rand(1, 1000),
'date' => '2018-01-01',
'type' => 'withdrawal',
@ -2319,5 +2321,4 @@ class TransactionControllerTest extends TestCase
$response = $this->post('/api/v1/transactions?include=tags', $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
}

View File

@ -31,8 +31,8 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class ConfigurationControllerTest

View File

@ -182,8 +182,8 @@ class AccountControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff:
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@ -222,7 +222,7 @@ class AccountControllerTest extends TestCase
public function testShowBrokenInitial()
{
// mock
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$date = new Carbon;
@ -244,8 +244,8 @@ class AccountControllerTest extends TestCase
public function testShowByDateEmpty(string $range)
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAccounts')->andReturnSelf();
@ -278,9 +278,9 @@ class AccountControllerTest extends TestCase
public function testShowInitial()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
@ -298,8 +298,8 @@ class AccountControllerTest extends TestCase
public function testStore()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -326,8 +326,8 @@ class AccountControllerTest extends TestCase
public function testStoreAnother()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -352,8 +352,8 @@ class AccountControllerTest extends TestCase
public function testUpdate()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -378,8 +378,8 @@ class AccountControllerTest extends TestCase
public function testUpdateAgain()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@ -25,8 +25,9 @@ namespace Tests\Feature\Controllers\Admin;
use FireflyIII\Models\LinkType;
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class LinkControllerTest
*
@ -226,7 +227,7 @@ class LinkControllerTest extends TestCase
public function testUpdateNonEditable()
{
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$linkType = LinkType::where('editable', 0)->first();
$linkType = LinkType::where('editable', 0)->first();
$data = [
'name' => 'test ' . rand(1, 1000),

View File

@ -28,9 +28,9 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Configuration;
use FireflyIII\Services\Github\Object\Release;
use FireflyIII\Services\Github\Request\UpdateRequest;
use Log;
use Mockery;
use Tests\TestCase;
use Log;
/**
* Class UpdateControllerTest

View File

@ -24,8 +24,9 @@ namespace Tests\Feature\Controllers\Admin;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class UserControllerTest
*

View File

@ -43,7 +43,7 @@ class AttachmentControllerTest extends TestCase
{
// mock stuff
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.delete', [1]));
@ -112,7 +112,7 @@ class AttachmentControllerTest extends TestCase
public function testEdit()
{
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.edit', [1]));

View File

@ -23,8 +23,8 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Auth;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Tests\TestCase;
use Log;
use Tests\TestCase;
/**
* Class ForgotPasswordControllerTest
@ -50,6 +50,7 @@ class ForgotPasswordControllerTest extends TestCase
*/
public function testSendResetLinkEmail()
{
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('hasRole')->andReturn(false)->once();
$data = [

View File

@ -24,9 +24,9 @@ namespace Tests\Feature\Controllers\Auth;
use FireflyIII\Models\Preference;
use Google2FA;
use Log;
use Preferences;
use Tests\TestCase;
use Log;
/**
* Class TwoFactorControllerTest

View File

@ -295,7 +295,7 @@ class BudgetControllerTest extends TestCase
{
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$accountRepos->shouldReceive('setUser');
@ -314,7 +314,7 @@ class BudgetControllerTest extends TestCase
{
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
$accountRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);

View File

@ -70,8 +70,8 @@ class CategoryControllerTest extends TestCase
{
// mock stuff
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@ -88,8 +88,8 @@ class CategoryControllerTest extends TestCase
{
// mock stuff
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('destroy')->andReturn(true);
@ -108,8 +108,8 @@ class CategoryControllerTest extends TestCase
{
// mock stuff
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@ -126,10 +126,10 @@ class CategoryControllerTest extends TestCase
public function testIndex()
{
// mock stuff
$category = factory(Category::class)->make();
$category = factory(Category::class)->make();
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$categoryRepos->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
$categoryRepos->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
@ -151,10 +151,10 @@ class CategoryControllerTest extends TestCase
public function testNoCategory(string $range)
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->twice()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
@ -188,10 +188,10 @@ class CategoryControllerTest extends TestCase
public function testNoCategoryAll(string $range)
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->twice()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
@ -224,10 +224,10 @@ class CategoryControllerTest extends TestCase
public function testNoCategoryDate(string $range)
{
// mock stuff
$collector = $this->mock(JournalCollectorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->twice()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
@ -267,10 +267,10 @@ class CategoryControllerTest extends TestCase
*/
public function testShow(string $range)
{
$transaction = factory(Transaction::class)->make();
$transaction = factory(Transaction::class)->make();
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->twice()->andReturn(new TransactionJournal);
// mock stuff

View File

@ -112,10 +112,10 @@ class BudgetControllerTest extends TestCase
public function testExpenseAsset(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
$collector->shouldReceive('setAllAssetAccounts')->once()->andReturnSelf();
@ -140,13 +140,12 @@ class BudgetControllerTest extends TestCase
*/
public function testExpenseCategory(string $range)
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$catRepos = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$catRepos = $this->mock(CategoryRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$categories = factory(Category::class, 10)->make();
@ -178,7 +177,7 @@ class BudgetControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$repository = $this->mock(BudgetRepositoryInterface::class);
$transactions = factory(Transaction::class, 10)->make();
$accounts = factory(Account::class, 10)->make();

View File

@ -52,8 +52,8 @@ class BudgetReportControllerTest extends TestCase
public function testAccountExpense()
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
@ -75,8 +75,8 @@ class BudgetReportControllerTest extends TestCase
public function testBudgetExpense()
{
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$pieChart->shouldReceive('setAccounts')->once()->andReturnSelf();
$pieChart->shouldReceive('setBudgets')->once()->andReturnSelf();

View File

@ -54,7 +54,7 @@ class CategoryControllerTest extends TestCase
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$firstUse = new Carbon;
$firstUse = new Carbon;
$firstUse->subDays(3);
$repository->shouldReceive('spentInPeriod')->andReturn('0');

View File

@ -46,8 +46,8 @@ class CurrencyControllerTest extends TestCase
{
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->once()->andReturn(false);
@ -106,8 +106,8 @@ class CurrencyControllerTest extends TestCase
{
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
@ -126,8 +126,8 @@ class CurrencyControllerTest extends TestCase
{
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -187,8 +187,8 @@ class CurrencyControllerTest extends TestCase
{
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);

View File

@ -22,14 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Tests\TestCase;
/**

View File

@ -81,7 +81,7 @@ class IndexControllerTest extends TestCase
public function testStart()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FileRoutine::class);
$routine = $this->mock(FileRoutine::class);
$routine->shouldReceive('setJob')->once();
$routine->shouldReceive('run')->once()->andReturn(true);
@ -97,7 +97,7 @@ class IndexControllerTest extends TestCase
public function testStartFailed()
{
$repository = $this->mock(ImportJobRepositoryInterface::class);
$routine = $this->mock(FileRoutine::class);
$routine = $this->mock(FileRoutine::class);
$routine->shouldReceive('setJob')->once();
$routine->shouldReceive('run')->once()->andReturn(false);

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;

View File

@ -22,10 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Report;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Helpers\Filter\InternalTransferFilter;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Tests\TestCase;
@ -43,7 +39,7 @@ class OperationsControllerTest extends TestCase
*/
public function testExpenses()
{
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('getExpenseReport')->andReturn([]);
$this->be($this->user());
@ -56,7 +52,7 @@ class OperationsControllerTest extends TestCase
*/
public function testIncome()
{
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('getIncomeReport')->andReturn([]);
$this->be($this->user());
@ -69,7 +65,7 @@ class OperationsControllerTest extends TestCase
*/
public function testOperations()
{
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('getExpenseReport')->andReturn([]);
$tasker->shouldReceive('getIncomeReport')->andReturn([]);

View File

@ -549,7 +549,7 @@ class ReportControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tag = $this->user()->tags()->find(1);
$tag = $this->user()->tags()->find(1);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('findNull')->andReturn($this->user()->accounts()->find(1))->twice();
$tagRepos->shouldReceive('findByTag')->andReturn($tag)->twice();
@ -603,7 +603,7 @@ class ReportControllerTest extends TestCase
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$generator = $this->mock(TYRG::class);
$tag = $this->user()->tags()->find(1);
$tag = $this->user()->tags()->find(1);
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));

View File

@ -47,7 +47,7 @@ class TagControllerTest extends TestCase
public function testCreate()
{
// mock stuff
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -63,7 +63,7 @@ class TagControllerTest extends TestCase
public function testDelete()
{
// mock stuff
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -96,7 +96,7 @@ class TagControllerTest extends TestCase
public function testEdit()
{
// mock stuff
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use DB;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@ -86,8 +85,8 @@ class BulkControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);
@ -122,8 +121,8 @@ class BulkControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.bulk.edit', join(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);

View File

@ -369,7 +369,7 @@ class ConvertControllerTest extends TestCase
{
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('convert')->andReturn(new MessageBag);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);

View File

@ -56,7 +56,7 @@ class LinkControllerTest extends TestCase
public function testDestroy()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$repository->shouldReceive('destroyLink');
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -127,7 +127,7 @@ class LinkControllerTest extends TestCase
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$data = [
$data = [
'link_other' => 0,
'link_type' => '1_inward',
];
@ -147,7 +147,7 @@ class LinkControllerTest extends TestCase
public function testSwitchLink()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('switchLink')->andReturn(false);
$this->be($this->user());

View File

@ -22,7 +22,6 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Transaction;
use DB;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@ -92,7 +91,7 @@ class MassControllerTest extends TestCase
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
$transfers = TransactionJournal::where('transaction_type_id', 3)->where('user_id', $this->user()->id)->take(2)->get();
$transfersArray = $transfers->pluck('id')->toArray();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
@ -113,7 +112,6 @@ class MassControllerTest extends TestCase
$budgetRepos->shouldReceive('getBudgets')->andReturn(new Collection);
$this->be($this->user());
$response = $this->get(route('transactions.mass.edit', $transfersArray));
$response->assertStatus(200);
@ -151,8 +149,8 @@ class MassControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.mass.edit', join(',', $allIds));
$allIds = $collection->pluck('id')->toArray();
$route = route('transactions.mass.edit', join(',', $allIds));
$this->be($this->user());
$response = $this->get($route);
$response->assertStatus(200);
@ -191,13 +189,13 @@ class MassControllerTest extends TestCase
// default transactions
$collection = $this->user()->transactionJournals()->take(4)->get();
$allIds = $collection->pluck('id')->toArray();
$allIds = $collection->pluck('id')->toArray();
$this->be($this->user());
$response = $this->get(route('transactions.mass.edit', join(',', $allIds)));
$response->assertStatus(200);
$response->assertSee('Edit a number of transactions');
$response->assertSessionHas('error','You have selected no valid transactions to edit.');
$response->assertSessionHas('error', 'You have selected no valid transactions to edit.');
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
}

View File

@ -33,7 +33,6 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;

View File

@ -271,8 +271,8 @@ class TransactionControllerTest extends TestCase
public function testShow()
{
// mock stuff
$tasker = $this->mock(JournalTaskerInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$tasker = $this->mock(JournalTaskerInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);
@ -291,8 +291,8 @@ class TransactionControllerTest extends TestCase
*/
public function testShowOpeningBalance()
{
$tasker = $this->mock(JournalTaskerInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$tasker = $this->mock(JournalTaskerInterface::class);
$linkRepos = $this->mock(LinkTypeRepositoryInterface::class);
$linkRepos->shouldReceive('get')->andReturn(new Collection);
$linkRepos->shouldReceive('getLinks')->andReturn(new Collection);

View File

@ -66,19 +66,6 @@ class BudgetFactoryTest extends TestCase
}
/**
* Put in unknown, get NULL
*
* @covers \FireflyIII\Factory\BudgetFactory
*/
public function testFindUnknown()
{
/** @var BudgetFactory $factory */
$factory = app(BudgetFactory::class);
$factory->setUser($this->user());
$this->assertNull($factory->find(null, 'I dont exist.'.rand(1,000)));
}
/**
* Put in NULL, will find NULL.
*
@ -94,4 +81,17 @@ class BudgetFactoryTest extends TestCase
}
/**
* Put in unknown, get NULL
*
* @covers \FireflyIII\Factory\BudgetFactory
*/
public function testFindUnknown()
{
/** @var BudgetFactory $factory */
$factory = app(BudgetFactory::class);
$factory->setUser($this->user());
$this->assertNull($factory->find(null, 'I dont exist.' . rand(1, 000)));
}
}

View File

@ -49,7 +49,8 @@ class TransactionCurrencyFactoryTest extends TestCase
*/
public function testFindByCode()
{
$currency = TransactionCurrency::find(1);
// ;
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find(null, $currency->code);
@ -61,7 +62,7 @@ class TransactionCurrencyFactoryTest extends TestCase
*/
public function testFindByID()
{
$currency = TransactionCurrency::find(1);
$currency = TransactionCurrency::inRandomOrder()->whereNull('deleted_at')->first();
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->find($currency->id, null);

View File

@ -258,9 +258,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadConfig()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -289,9 +289,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadInvalid()
{
// data
$config = ['stage' => 'ksksjje'];
$config = ['stage' => 'ksksjje'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -313,9 +313,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadMap()
{
// data:
$config = ['stage' => 'map'];
$config = ['stage' => 'map'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -344,9 +344,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadReady()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -368,9 +368,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextDataUploadRoles()
{
// data
$config = ['stage' => 'roles'];
$config = ['stage' => 'roles'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -397,9 +397,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewInitial()
{
// data
$config = ['stage' => 'initial'];
$config = ['stage' => 'initial'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -426,9 +426,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewInvalid()
{
// data
$config = ['stage' => 'slkds903ms90k'];
$config = ['stage' => 'slkds903ms90k'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -450,9 +450,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewMap()
{
// data
$config = ['stage' => 'map'];
$config = ['stage' => 'map'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -491,9 +491,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewReady()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -515,9 +515,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewRoles()
{
// data
$config = ['stage' => 'roles'];
$config = ['stage' => 'roles'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -542,9 +542,9 @@ class FileConfiguratorTest extends TestCase
public function testGetNextViewUploadConfig()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -569,9 +569,9 @@ class FileConfiguratorTest extends TestCase
public function testGetWarningMessage()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -609,9 +609,9 @@ class FileConfiguratorTest extends TestCase
public function testIsJobConfiguredFalse()
{
// data
$config = ['stage' => 'upload-config'];
$config = ['stage' => 'upload-config'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);
@ -648,9 +648,9 @@ class FileConfiguratorTest extends TestCase
public function testIsJobConfiguredTrue()
{
// data
$config = ['stage' => 'ready'];
$config = ['stage' => 'ready'];
$extended = ['steps' => 0, 'done' => 0];
$job = $this->getJob($config);
$job = $this->getJob($config);
// mock repos
$repository = $this->mock(ImportJobRepositoryInterface::class);

View File

@ -155,7 +155,7 @@ class AmountTest extends TestCase
'€1,44' => '1.44',
'(33.52)' => '-33.52',
'€(63.12)' => '-63.12',
'($182.77)' => '-182.77',
'($182.77)' => '-182.77',
];
foreach ($values as $value => $expected) {
$converter = new Amount;

View File

@ -57,7 +57,7 @@ class AssetAccountIbansTest extends TestCase
$this->assertCount(3, $mapping);
// assert this is what the result looks like:
$result = [
0 => strval(trans('import.map_do_not_map')),
0 => strval(trans('import.map_do_not_map')),
53 => 'Else',
17 => 'IBAN (Something)',
];

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\Import\MapperPreProcess;
use FireflyIII\Import\MapperPreProcess\TagsComma;
use FireflyIII\Import\MapperPreProcess\TagsSpace;
use Tests\TestCase;

View File

@ -1232,7 +1232,7 @@ class BinderTest extends TestCase
{
$tagRepos = $this->mock(TagRepositoryInterface::class);
$tagRepos->shouldReceive('setUser');
$tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
$tags = $this->user()->tags()->whereIn('id', [1, 2])->get(['tags.*']);
$tagRepos->shouldReceive('get')->once()->andReturn($tags);
Route::middleware(Binder::class)->any(
@ -1244,7 +1244,6 @@ class BinderTest extends TestCase
$names = join(',', $tags->pluck('tag')->toArray());
$this->be($this->user());
$response = $this->get('/_test/binder/' . $names);
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());

View File

@ -46,7 +46,6 @@ class IsDemoUserTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Middleware\IsDemoUser::handle
*/

View File

@ -0,0 +1,99 @@
<?php
/**
* AccountDestroyServiceClass.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Destroy;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Services\Internal\Destroy\AccountDestroyService;
use FireflyIII\Services\Internal\Destroy\JournalDestroyService;
use Tests\TestCase;
/**
* Class AccountDestroyServiceTest
*/
class AccountDestroyServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyBasic()
{
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, null);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
}
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyDontMove()
{
// create objects:
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
// mock delete service:
$service = $this->mock(JournalDestroyService::class);
$service->shouldReceive('destroy')->once();
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, null);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
}
/**
* @covers \FireflyIII\Services\Internal\Destroy\AccountDestroyService
*/
public function testDestroyMove()
{
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$move = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$transaction = Transaction::create(['account_id' => $account->id, 'transaction_journal_id' => 1, 'amount' => 10, 'transaction_currency_id' => 1]);
/** @var AccountDestroyService $service */
$service = app(AccountDestroyService::class);
$service->destroy($account, $move);
$this->assertDatabaseMissing('accounts', ['id' => $account->id, 'deleted_at' => null]);
$this->assertDatabaseMissing('transactions', ['account_id' => $account->id]);
$this->assertDatabaseHas('transactions', ['id' => $transaction->id, 'account_id' => $move->id]);
}
}

View File

@ -0,0 +1,199 @@
<?php
/**
* AccountUpdateServiceTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Update;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Note;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Update\AccountUpdateService;
use Tests\TestCase;
/**
* Class AccountUpdateServiceTest
*/
class AccountUpdateServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testDeleteExistingIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
$journal = TransactionJournal::create(
['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
'date' => '2018-01-01', 'completed' => true,
]
);
// transactions:
Transaction::create(
['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
);
Transaction::create(
['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(0, $account->transactions()->count());
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateBasic()
{
/** @var Account $account */
$account = $this->user()->accounts()->first();
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateExistingIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$opposing = $this->user()->accounts()->first();
$journal = TransactionJournal::create(
['user_id' => $this->user()->id, 'transaction_type_id' => 4, 'transaction_currency_id' => 1, 'description' => 'IB',
'date' => '2018-01-01', 'completed' => true,
]
);
// transactions:
Transaction::create(
['account_id' => $account->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '100', 'identifier' => 0,]
);
Transaction::create(
['account_id' => $opposing->id, 'transaction_journal_id' => $journal->id,
'transaction_currency_id' => 1, 'amount' => '-100', 'identifier' => 0,]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'openingBalance' => '105',
'openingBalanceDate' => new Carbon('2018-01-01'),
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(105, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
/**
* @covers \FireflyIII\Services\Internal\Update\AccountUpdateService
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
*/
public function testUpdateNewIB()
{
/** @var Account $account */
$account = Account::create(
['user_id' => $this->user()->id, 'account_type_id' => 1, 'name' => 'Some name #' . rand(1, 1000),
'virtual_balance' => '0', 'iban' => null, 'active' => true]
);
$data = [
'name' => 'Some new name #' . rand(1, 1000),
'active' => true,
'virtualBalance' => '0',
'iban' => null,
'accountRole' => 'defaultAsset',
'openingBalance' => '100',
'openingBalanceDate' => new Carbon('2018-01-01'),
'notes' => 'Hello',
'currency_id' => 1,
];
/** @var AccountUpdateService $service */
$service = app(AccountUpdateService::class);
$account = $service->update($account, $data);
$this->assertEquals($data['name'], $account->name);
$this->assertEquals(1, $account->transactions()->count());
$this->assertEquals(100, $account->transactions()->first()->amount);
/** @var Note $note */
$note = $account->notes()->first();
$this->assertEquals($data['notes'], $note->text);
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* JournalUpdateServiceTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Services\Internal\Update;
use Carbon\Carbon;
use FireflyIII\Factory\BillFactory;
use FireflyIII\Factory\TagFactory;
use FireflyIII\Factory\TransactionFactory;
use FireflyIII\Factory\TransactionJournalMetaFactory;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Services\Internal\Update\JournalUpdateService;
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
use Tests\TestCase;
/**
* Class JournalUpdateServiceTest
*/
class JournalUpdateServiceTest extends TestCase
{
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
*/
public function testUpdateBasic()
{
// mock other stuff:
$transactionFactory = $this->mock(TransactionFactory::class);
$transactionService = $this->mock(TransactionUpdateService::class);
$billFactory = $this->mock(BillFactory::class);
$tagFactory = $this->mock(TagFactory::class);
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
// mock calls
$billFactory->shouldReceive('setUser');
$billFactory->shouldReceive('find')->andReturn(null);
$transactionService->shouldReceive('setUser');
$transactionFactory->shouldReceive('setUser');
$tagFactory->shouldReceive('setUser');
$metaFactory->shouldReceive('setUser');
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
$data = [
'description' => 'Updated journal #' . rand(1, 1000),
'date' => new Carbon('2018-01-01'),
'bill_id' => null,
'bill_name' => null,
'tags' => [],
'notes' => 'Hello',
'transactions' => [],
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$result = $service->update($journal, $data);
$this->assertEquals($data['description'], $result->description);
$this->assertEquals(0, $result->transactions()->count());
}
/**
* @covers \FireflyIII\Services\Internal\Update\JournalUpdateService
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
*/
public function testUpdateLotsOfTransactions()
{
// mock other stuff:
$transactionFactory = $this->mock(TransactionFactory::class);
$transactionService = $this->mock(TransactionUpdateService::class);
$billFactory = $this->mock(BillFactory::class);
$tagFactory = $this->mock(TagFactory::class);
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
// mock calls
$billFactory->shouldReceive('setUser');
$billFactory->shouldReceive('find')->andReturn(null);
$transactionService->shouldReceive('setUser');
$transactionFactory->shouldReceive('setUser');
$transactionService->shouldReceive('update')->times(2);
$transactionFactory->shouldReceive('createPair')->times(2);
$tagFactory->shouldReceive('setUser');
$metaFactory->shouldReceive('setUser');
/** @var TransactionJournal $journal */
$journal = $this->user()->transactionJournals()->skip(4)->where('transaction_type_id', 1)->first();
$data = [
'description' => 'Updated journal #' . rand(1, 1000),
'date' => new Carbon('2018-01-01'),
'bill_id' => null,
'bill_name' => null,
'tags' => [],
'notes' => 'Hello',
'transactions' => [
['identifier' => 0],
['identifier' => 1],
['identifier' => 2],
],
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$result = $service->update($journal, $data);
$this->assertEquals($data['description'], $result->description);
$this->assertEquals(2, $result->transactions()->count());
}
}

View File

@ -39,14 +39,17 @@ class AddTagTest extends TestCase
*/
public function testActExistingTag()
{
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
$tag = Tag::inRandomOrder()->whereNull('deleted_at')->first();
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->sync([$tag->id]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
$ruleAction = new RuleAction;
$ruleAction->action_value = 'housing';
$journal = TransactionJournal::find(1);
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$ruleAction->action_value = $tag->tag;
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => 2, 'transaction_journal_id' => 1]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
}
/**
@ -54,15 +57,15 @@ class AddTagTest extends TestCase
*/
public function testActNoTag()
{
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$ruleAction = new RuleAction;
$ruleAction->action_value = 'TestTag-' . rand(1, 1000);
$journal = TransactionJournal::find(1);
$action = new AddTag($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
// find newly created tag:
$tag = Tag::orderBy('id', 'DESC')->first();
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => 1]);
$this->assertDatabaseHas('tag_transaction_journal', ['tag_id' => $tag->id, 'transaction_journal_id' => $journal->id]);
}
}

View File

@ -41,13 +41,13 @@ class AppendDescriptionTest extends TestCase
$ruleAction = new RuleAction;
$ruleAction->action_value = 'APPEND';
$journal = TransactionJournal::find(1);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$oldDescription = $journal->description;
$action = new AppendDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(1);
$journal = TransactionJournal::find($journal->id);
$this->assertEquals($oldDescription . 'APPEND', $journal->description);
}
}

View File

@ -39,7 +39,7 @@ class ClearBudgetTest extends TestCase
public function testAct()
{
// associate budget with journal:
$journal = TransactionJournal::find(5);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->save($budget);
$this->assertGreaterThan(0, $journal->budgets()->count());

View File

@ -39,7 +39,7 @@ class ClearCategoryTest extends TestCase
public function testAct()
{
// associate budget with journal:
$journal = TransactionJournal::find(5);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->budgets()->save($category);
$this->assertGreaterThan(0, $journal->categories()->count());

View File

@ -40,7 +40,7 @@ class ClearNotesTest extends TestCase
public function testAct()
{
// give journal a note:
$journal = TransactionJournal::find(6);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
$note = new Note;

View File

@ -41,7 +41,7 @@ class PrependDescriptionTest extends TestCase
// get journal, give fixed description
$description = 'text' . rand(1, 1000);
$prepend = 'prepend' . rand(1, 1234);
$journal = TransactionJournal::find(7);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
$journal->save();
@ -51,7 +51,7 @@ class PrependDescriptionTest extends TestCase
$action = new PrependDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(7);
$journal = TransactionJournal::find($journal->id);
// assert result
$this->assertEquals($prepend . $description, $journal->description);

View File

@ -40,7 +40,7 @@ class PrependNotesTest extends TestCase
public function testAct()
{
// give journal some notes.
$journal = TransactionJournal::find(8);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
$start = 'Default note text';
$toPrepend = 'This is prepended';
@ -69,7 +69,7 @@ class PrependNotesTest extends TestCase
public function testActNewNote()
{
// give journal some notes.
$journal = TransactionJournal::find(4);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (!is_null($note)) {
$note->forceDelete();

View File

@ -68,7 +68,7 @@ class RemoveTagTest extends TestCase
{
// get journal, link al tags:
/** @var TransactionJournal $journal */
$journal = TransactionJournal::find(11);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tags = $journal->user->tags()->get();
$journal->tags()->sync($tags->pluck('id')->toArray());
$this->assertEquals($tags->count(), $journal->tags()->get()->count());

View File

@ -41,7 +41,7 @@ class SetBudgetTest extends TestCase
public function testAct()
{
// get journal, remove all budgets
$journal = TransactionJournal::find(12);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');

View File

@ -24,7 +24,6 @@ namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetCategory;
use Tests\TestCase;
@ -40,7 +39,7 @@ class SetCategoryTest extends TestCase
public function testAct()
{
// get journal, remove all budgets
$journal = TransactionJournal::find(13);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());

View File

@ -41,7 +41,7 @@ class SetDescriptionTest extends TestCase
// get journal, give fixed description
$description = 'text' . rand(1, 1000);
$newDescription = 'new description' . rand(1, 1234);
$journal = TransactionJournal::find(14);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->description = $description;
$journal->save();
@ -51,7 +51,7 @@ class SetDescriptionTest extends TestCase
$action = new SetDescription($ruleAction);
$result = $action->act($journal);
$this->assertTrue($result);
$journal = TransactionJournal::find(14);
$journal = TransactionJournal::find($journal->id);
// assert result
$this->assertEquals($newDescription, $journal->description);

View File

@ -95,8 +95,8 @@ class SetDestinationAccountTest extends TestCase
*/
public function testActWithdrawalExisting()
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::WITHDRAWAL)->first();
// select split transactions to exclude them later:
$set = TransactionJournal::where('transaction_type_id', $type->id)->get(['transaction_journals.*']);

View File

@ -40,7 +40,7 @@ class SetNotesTest extends TestCase
public function testAct()
{
// give journal a note:
$journal = TransactionJournal::find(15);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$note = $journal->notes()->first();
if (is_null($note)) {
$note = new Note;
@ -69,7 +69,7 @@ class SetNotesTest extends TestCase
public function testActNoNotes()
{
// give journal a note:
$journal = TransactionJournal::find(16);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->forceDelete();
$this->assertEquals(0, $journal->notes()->count());

View File

@ -49,7 +49,7 @@ class SetSourceAccountTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
$type = TransactionType::whereType(TransactionType::DEPOSIT)->first();
// select split transactions to exclude them later:
$set = TransactionJournal::where('transaction_type_id', $type->id)->get(['transaction_journals.*']);
@ -107,11 +107,11 @@ class SetSourceAccountTest extends TestCase
}
}
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$sourceTr = $journal->transactions()->where('amount', '<', 0)->first();
$source = $sourceTr->account;
$user = $journal->user;
$accountType = AccountType::whereType(AccountType::ASSET)->first();
$account = $user->accounts()->where('account_type_id', $accountType->id)->where('id', '!=', $source->id)->first();
$this->assertNotEquals($source->id, $account->id);

View File

@ -36,7 +36,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@ -52,7 +52,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$otherBudget = $journal->user->budgets()->where('id', '!=', $budget->id)->first();
$journal->budgets()->detach();
@ -69,7 +69,7 @@ class BudgetIsTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();

View File

@ -36,7 +36,7 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredJournal()
{
$journal = TransactionJournal::find(17);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@ -52,7 +52,7 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredNotJournal()
{
$journal = TransactionJournal::find(18);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$otherCategory = $journal->user->categories()->where('id', '!=', $category->id)->first();
$journal->categories()->detach();
@ -69,11 +69,12 @@ class CategoryIsTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(19);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$transaction->categories()->detach();
$transaction->categories()->save($category);
$this->assertEquals(0, $journal->categories()->count());
$this->assertEquals(1, $transaction->categories()->count());

View File

@ -36,8 +36,12 @@ class FromAccountContainsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(20);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '<', 0)->count();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
}
$account = $transaction->account;
$trigger = FromAccountContains::makeFromStrings($account->name, false);
@ -50,7 +54,7 @@ class FromAccountContainsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(21);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,8 +36,12 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '<', 0)->count();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
}
$account = $transaction->account;
$trigger = FromAccountEnds::makeFromStrings(substr($account->name, -3), false);
@ -50,7 +54,7 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@ -64,7 +68,7 @@ class FromAccountEndsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountEnds::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class FromAccountIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@ -50,7 +50,7 @@ class FromAccountIsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@ -50,7 +50,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(22);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
$account = $transaction->account;
@ -64,7 +64,7 @@ class FromAccountStartsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(23);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = FromAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@ -52,7 +52,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
$trigger = HasAnyBudget::makeFromStrings('', false);
@ -65,7 +65,7 @@ class HasAnyBudgetTest extends TestCase
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());

View File

@ -36,7 +36,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@ -52,7 +52,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
$trigger = HasAnyCategory::makeFromStrings('', false);
@ -65,7 +65,7 @@ class HasAnyCategoryTest extends TestCase
*/
public function testTriggeredTransactions()
{
$journal = TransactionJournal::find(26);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());

View File

@ -36,7 +36,7 @@ class HasAnyTagTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(25);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);
@ -52,7 +52,7 @@ class HasAnyTagTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(24);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
$trigger = HasAnyTag::makeFromStrings('', false);

View File

@ -36,7 +36,13 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(26);
$count = 0;
while($count === 0) {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
}
$attachment = $journal->user->attachments()->first();
$journal->attachments()->save($attachment);
$this->assertEquals(1, $journal->attachments()->count());
@ -51,7 +57,13 @@ class HasAttachmentTest extends TestCase
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(27);
$count = 0;
while ($count === 0) {
// this is kind of cheating but OK.
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->attachments()->count();
}
$this->assertEquals(0, $journal->attachments()->count());
$trigger = HasAttachment::makeFromStrings('1', false);

View File

@ -36,7 +36,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredBudget()
{
$journal = TransactionJournal::find(28);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$budget = $journal->user->budgets()->first();
$journal->budgets()->detach();
$journal->budgets()->save($budget);
@ -52,7 +52,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredNoBudget()
{
$journal = TransactionJournal::find(29);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());
@ -66,7 +66,7 @@ class HasNoBudgetTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(30);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$budget = $journal->user->budgets()->first();

View File

@ -36,7 +36,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredCategory()
{
$journal = TransactionJournal::find(31);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$category = $journal->user->categories()->first();
$journal->categories()->detach();
$journal->categories()->save($category);
@ -52,7 +52,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredNoCategory()
{
$journal = TransactionJournal::find(32);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->categories()->detach();
$this->assertEquals(0, $journal->categories()->count());
@ -66,7 +66,7 @@ class HasNoCategoryTest extends TestCase
*/
public function testTriggeredTransaction()
{
$journal = TransactionJournal::find(33);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->first();
$category = $journal->user->categories()->first();

View File

@ -36,7 +36,7 @@ class HasNoTagTest extends TestCase
*/
public function testTriggeredNoTag()
{
$journal = TransactionJournal::find(34);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
@ -50,7 +50,7 @@ class HasNoTagTest extends TestCase
*/
public function testTriggeredTag()
{
$journal = TransactionJournal::find(35);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$tag = $journal->user->tags()->first();
$journal->tags()->detach();
$journal->tags()->save($tag);

View File

@ -37,7 +37,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(36);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -53,7 +53,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(37);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -69,7 +69,7 @@ class NotesAnyTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(38);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesAny::makeFromStrings('', false);
$result = $trigger->triggered($journal);

View File

@ -37,7 +37,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(39);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -53,7 +53,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(41);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -69,7 +69,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(40);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -85,7 +85,7 @@ class NotesAreTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(42);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesAre::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);

View File

@ -37,7 +37,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(43);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -53,7 +53,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredDifferent()
{
$journal = TransactionJournal::find(46);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -69,7 +69,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(44);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -85,7 +85,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredNone()
{
$journal = TransactionJournal::find(47);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesContain::makeFromStrings('Bla bla', false);
$result = $trigger->triggered($journal);
@ -97,7 +97,7 @@ class NotesContainTest extends TestCase
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(45);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@ -37,7 +37,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(48);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$trigger = NotesEmpty::makeFromStrings('', false);
$result = $trigger->triggered($journal);
@ -49,7 +49,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggeredEmpty()
{
$journal = TransactionJournal::find(49);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -65,7 +65,7 @@ class NotesEmptyTest extends TestCase
*/
public function testTriggeredPartial()
{
$journal = TransactionJournal::find(50);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@ -37,7 +37,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(51);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -53,7 +53,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(53);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -69,7 +69,7 @@ class NotesEndTest extends TestCase
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(52);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@ -37,7 +37,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(54);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -53,7 +53,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(55);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);
@ -69,7 +69,7 @@ class NotesStartTest extends TestCase
*/
public function testTriggeredNoMatch()
{
$journal = TransactionJournal::find(56);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->notes()->delete();
$note = new Note();
$note->noteable()->associate($journal);

View File

@ -36,7 +36,7 @@ class TagIsTest extends TestCase
*/
public function testNotTriggered()
{
$journal = TransactionJournal::find(58);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$this->assertEquals(0, $journal->tags()->count());
@ -50,7 +50,7 @@ class TagIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(57);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$journal->tags()->detach();
$tags = $journal->user->tags()->take(3)->get();
$search = '';

View File

@ -36,7 +36,7 @@ class ToAccountContainsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(59);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$trigger = ToAccountContains::makeFromStrings($account->name, false);
@ -49,7 +49,7 @@ class ToAccountContainsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(60);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountContains::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);

View File

@ -36,10 +36,14 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(61);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '>', 0)->count();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
}
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings(substr($account->name, -3), false);
$result = $trigger->triggered($journal);
$this->assertTrue($result);
@ -50,8 +54,12 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(62);
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$count = 0;
while ($count === 0) {
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$count = $journal->transactions()->where('amount', '>', 0)->count();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
}
$account = $transaction->account;
$trigger = ToAccountEnds::makeFromStrings('bla-bla-bla' . $account->name, false);
@ -64,7 +72,7 @@ class ToAccountEndsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(63);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountEnds::makeFromStrings(strval(rand(1, 234)), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class ToAccountIsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(64);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@ -50,7 +50,7 @@ class ToAccountIsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(65);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountIs::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(66);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@ -50,7 +50,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggeredLonger()
{
$journal = TransactionJournal::find(67);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$account = $transaction->account;
@ -64,7 +64,7 @@ class ToAccountStartsTest extends TestCase
*/
public function testTriggeredNot()
{
$journal = TransactionJournal::find(68);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = ToAccountStarts::makeFromStrings('some name' . rand(1, 234), false);
$result = $trigger->triggered($journal);

View File

@ -36,7 +36,7 @@ class TransactionTypeTest extends TestCase
*/
public function testTriggered()
{
$journal = TransactionJournal::find(69);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$type = $journal->transactionType->type;
$trigger = TransactionType::makeFromStrings($type, false);
$result = $trigger->triggered($journal);
@ -48,7 +48,7 @@ class TransactionTypeTest extends TestCase
*/
public function testTriggeredFalse()
{
$journal = TransactionJournal::find(70);
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
$trigger = TransactionType::makeFromStrings('NonExisting', false);
$result = $trigger->triggered($journal);
$this->assertFalse($result);

View File

@ -111,8 +111,8 @@ class PiggyBankEventTransformerTest extends TestCase
$accountMeta = AccountMeta::create(
[
'account_id' => $account->id,
'name' => 'currency_id',
'data' => 1,
'name' => 'currency_id',
'data' => 1,
]
);