firefly-iii/tests/Unit/Transformers/AttachmentTransformerTest.php

90 lines
2.9 KiB
PHP
Raw Normal View History

<?php
/**
* AttachmentTransformerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* 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/>.
*/
declare(strict_types=1);
namespace Tests\Unit\Transformers;
use FireflyIII\Models\Attachment;
2018-12-18 12:57:23 -06:00
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Transformers\AttachmentTransformer;
use Log;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
/**
* Class AttachmentTransformerTest
2019-08-17 03:48:28 -05:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AttachmentTransformerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Test basic transformer
*
2018-08-09 13:17:15 -05:00
* @covers \FireflyIII\Transformers\AttachmentTransformer
*/
2018-05-11 12:58:10 -05:00
public function testBasic(): void
{
2018-12-18 12:57:23 -06:00
$repository = $this->mock(AttachmentRepositoryInterface::class);
2019-07-31 09:53:09 -05:00
$md5 = md5('hello' . $this->randomInt());
$attachment = Attachment::create(
[
'user_id' => $this->user()->id,
'attachable_id' => 1,
2018-12-18 12:57:23 -06:00
'attachable_type' => TransactionJournal::class,
'md5' => $md5,
'filename' => 'hello.txt',
'mime' => 'text/plain',
'size' => 101,
'uploaded' => 1,
]
);
2018-12-18 12:57:23 -06:00
// expected calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('getNoteText')->once()->andReturn('I am a note');
// make transformer
$transformer = app(AttachmentTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($attachment);
// test results
$this->assertEquals($attachment->id, $result['id']);
$this->assertEquals('TransactionJournal', $result['attachable_type']);
$this->assertEquals('I am a note', $result['notes']);
}
2018-03-04 08:14:29 -06:00
}