. */ declare(strict_types=1); namespace Tests\Unit\Console\Commands\Upgrade; use FireflyConfig; use FireflyIII\Models\Configuration; use FireflyIII\Models\TransactionJournalMeta; use Log; use Tests\TestCase; /** * Class MigrateJournalNotesTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class MigrateJournalNotesTest extends TestCase { /** * */ public function setUp(): void { 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; FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false); FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]); // 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; FireflyConfig::shouldReceive('get')->withArgs(['480_migrate_notes', false])->andReturn($false); FireflyConfig::shouldReceive('set')->withArgs(['480_migrate_notes', true]); $journal = $this->getRandomWithdrawal(); // delete any notes the journal may have already: $journal->notes()->forceDelete(); $meta = TransactionJournalMeta::create( [ '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()); } }