Cover all transformers.

This commit is contained in:
James Cole
2018-12-20 22:03:34 +01:00
parent 84b3195e9b
commit 27bc03fc20
12 changed files with 443 additions and 1533 deletions

View File

@@ -53,8 +53,10 @@ class TagTransformerTest extends TestCase
'zoomLevel' => 3,
]
);
$transformer = new TagTransformer(new ParameterBag);
$result = $transformer->transform($tag);
$transformer = app(TagTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($tag);
$this->assertEquals($tag->tag, $result['tag']);
$this->assertEquals(5.5, $result['latitude']);
$this->assertEquals(6.6, $result['longitude']);

View File

@@ -0,0 +1,66 @@
<?php
/**
* TransactionLinkTransformerTest.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 Carbon\Carbon;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Transformers\TransactionLinkTransformer;
use FireflyIII\Transformers\TransactionTransformer;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
/**
* Class TransactionLinkTransformerTest
*/
class TransactionLinkTransformerTest extends TestCase
{
/**
* Test basic tag transformer
*
* @covers \FireflyIII\Transformers\TransactionLinkTransformer
*/
public function testBasic(): void
{
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('getLinkNoteText')->atLeast()->once()->andReturn('abc');
/** @var TransactionJournalLink $link */
$link = TransactionJournalLink::first();
$transformer = app(TransactionLinkTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($link);
$this->assertEquals($link->source_id, $result['inward_id']);
$this->assertEquals('abc', $result['notes']);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace Tests\Unit\Transformers;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\UserTransformer;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
@@ -41,27 +42,15 @@ class UserTransformerTest extends TestCase
*/
public function testBasic(): void
{
$user = $this->user();
$transformer = new UserTransformer(new ParameterBag());
$result = $transformer->transform($user);
$repository = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getRoleByUser')->atLeast()->once()->andReturn('owner');
$user = $this->user();
$transformer = app(UserTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($user);
$this->assertEquals($user->email, $result['email']);
$this->assertEquals('owner', $result['role']);
}
/**
* Test basic transformer.
*
* @covers \FireflyIII\Transformers\UserTransformer
*/
public function testEmptyUser(): void
{
$user = $this->emptyUser();
$transformer = new UserTransformer(new ParameterBag());
$result = $transformer->transform($user);
$this->assertEquals($user->email, $result['email']);
$this->assertNull($result['role']);
}
}