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

87 lines
2.7 KiB
PHP
Raw Normal View History

<?php
/**
* AttachmentTransformerTest.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\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
*/
class AttachmentTransformerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
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);
2018-03-28 12:38:20 -05:00
$md5 = md5('hello' . random_int(1, 10000));
$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
}