Files
firefly-iii/tests/Feature/Console/Commands/Upgrade/TransactionIdentifierTest.php

162 lines
5.6 KiB
PHP
Raw Normal View History

2019-06-13 07:17:31 +02:00
<?php
/**
* TransactionIdentifierTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-08-17 12:09:03 +02:00
declare(strict_types=1);
2019-06-13 07:17:31 +02:00
namespace Tests\Unit\Console\Commands\Upgrade;
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
2019-08-10 14:41:08 +02:00
use FireflyIII\Repositories\Journal\JournalCLIRepositoryInterface;
2019-06-13 07:17:31 +02:00
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Tests\TestCase;
/**
* Class TransactionIdentifierTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2019-06-13 07:17:31 +02:00
*/
class TransactionIdentifierTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
2020-07-30 20:49:40 +02:00
self::markTestIncomplete('Incomplete for refactor.');
return;
2019-06-13 07:17:31 +02:00
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
*/
public function testHandle(): void
{
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2019-08-10 14:41:08 +02:00
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
2019-06-13 07:17:31 +02:00
// commands:
2019-08-10 14:41:08 +02:00
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection)
2019-06-13 07:17:31 +02:00
->atLeast()->once();
// configuration
$false = new Configuration;
$false->data = false;
2019-08-29 17:53:25 +02:00
FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
2019-06-13 07:17:31 +02:00
// assume all is well.
$this->artisan('firefly-iii:transaction-identifiers')
->expectsOutput('All split journal transaction identifiers are correct.')
->assertExitCode(0);
}
/**
* Basic test. Assume nothing is wrong.
*
* @covers \FireflyIII\Console\Commands\Upgrade\TransactionIdentifier
*/
public function testHandleSplit(): void
{
// create a split journal:
$asset = $this->getRandomAsset();
$expense = $this->getRandomExpense();
$journal = TransactionJournal::create(
[
'user_id' => 1,
'transaction_currency_id' => 1,
'transaction_type_id' => 1,
'description' => 'Test',
'tag_count' => 0,
'date' => '2019-01-01',
]
);
$one = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-10',
'identifier' => 0,
]
);
$two = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '10',
'identifier' => 0,
]
);
$three = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $asset->id,
'amount' => '-12',
'identifier' => 0,
]
);
$four = Transaction::create(
[
'transaction_journal_id' => $journal->id,
'account_id' => $expense->id,
'amount' => '12',
'identifier' => 0,
]
);
// mock classes:
$journalRepos = $this->mock(JournalRepositoryInterface::class);
2019-08-10 14:41:08 +02:00
$cliRepos = $this->mock(JournalCLIRepositoryInterface::class);
2019-06-13 07:17:31 +02:00
// commands:
2019-08-10 14:41:08 +02:00
$cliRepos->shouldReceive('getSplitJournals')->andReturn(new Collection([$journal]))
2019-06-13 07:17:31 +02:00
->atLeast()->once();
// configuration
$false = new Configuration;
$false->data = false;
2019-08-29 17:53:25 +02:00
FireflyConfig::shouldReceive('get')->withArgs(['480_transaction_identifier', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_transaction_identifier', true]);
2019-06-13 07:17:31 +02:00
// assume all is well.
$this->artisan('firefly-iii:transaction-identifiers')
2019-06-13 18:07:49 +02:00
->expectsOutput('Fixed 2 split journal transaction identifier(s).')
2019-06-13 07:17:31 +02:00
->assertExitCode(0);
// see results:
$this->assertCount(1, Transaction::where('id', $one->id)->where('identifier', 0)->get());
$this->assertCount(1, Transaction::where('id', $three->id)->where('identifier', 1)->get());
}
2019-08-17 12:09:03 +02:00
}