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

107 lines
3.3 KiB
PHP
Raw Normal View History

2019-06-13 06:39:05 +02:00
<?php
/**
* MigrateJournalNotesTest.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 06:39:05 +02:00
2020-08-01 05:32:17 +02:00
namespace Tests\Feature\Console\Commands\Upgrade;
2019-06-13 06:39:05 +02:00
use FireflyConfig;
use FireflyIII\Models\Configuration;
use FireflyIII\Models\TransactionJournalMeta;
use Log;
use Tests\TestCase;
/**
* Class MigrateJournalNotesTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2019-06-13 06:39:05 +02:00
*/
class MigrateJournalNotesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
2020-07-30 20:49:40 +02:00
self::markTestIncomplete('Incomplete for refactor.');
return;
2019-06-13 06:39:05 +02:00
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
2019-08-29 17:53:25 +02:00
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
2019-06-13 06:39:05 +02:00
// assume all is well.
$this->artisan('firefly-iii:migrate-notes')
->expectsOutput('No notes to migrate.')
->assertExitCode(0);
}
/**
* @covers \FireflyIII\Console\Commands\Upgrade\MigrateJournalNotes
*/
public function testHandleNote(): void
{
$false = new Configuration;
$false->data = false;
2019-08-29 17:53:25 +02:00
FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]);
2019-06-13 06:39:05 +02:00
$journal = $this->getRandomWithdrawal();
2019-06-29 08:14:28 +02:00
// delete any notes the journal may have already:
$journal->notes()->forceDelete();
$meta = TransactionJournalMeta::create(
2019-06-13 06:39:05 +02:00
[
'transaction_journal_id' => $journal->id,
'name' => 'notes',
'data' => json_encode('Some note.'),
'hash' => 'Some hash',
]
);
// assume one is fixed.
$this->artisan('firefly-iii:migrate-notes')
->expectsOutput('Migrated 1 note(s).')
->assertExitCode(0);
$this->assertCount(0, TransactionJournalMeta
::where('name', 'notes')
->where('id', $meta->id)
->whereNull('deleted_at')
->get());
}
2019-08-17 12:09:03 +02:00
}