mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix tests to catch use of repositories
This commit is contained in:
parent
7109fd8196
commit
e2d1de94b7
@ -2377,9 +2377,13 @@ class TransactionControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdateBasicDeposit()
|
public function testUpdateBasicDeposit()
|
||||||
{
|
{
|
||||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
$data = [
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('setUser');
|
||||||
|
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
|
||||||
|
|
||||||
|
$data = [
|
||||||
'description' => 'Some deposit #' . rand(1, 1000),
|
'description' => 'Some deposit #' . rand(1, 1000),
|
||||||
'date' => '2018-01-01',
|
'date' => '2018-01-01',
|
||||||
'transactions' => [
|
'transactions' => [
|
||||||
@ -2416,6 +2420,11 @@ class TransactionControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
|
||||||
$repository = $this->mock(JournalRepositoryInterface::class);
|
$repository = $this->mock(JournalRepositoryInterface::class);
|
||||||
|
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('setUser');
|
||||||
|
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$account->id]])->andReturn(new Collection([$account]));
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'description' => 'Some transaction #' . rand(1, 1000),
|
'description' => 'Some transaction #' . rand(1, 1000),
|
||||||
'date' => '2018-01-01',
|
'date' => '2018-01-01',
|
||||||
@ -2433,6 +2442,8 @@ class TransactionControllerTest extends TestCase
|
|||||||
$count = $withdrawal->transactions()->count();
|
$count = $withdrawal->transactions()->count();
|
||||||
} while ($count !== 2);
|
} while ($count !== 2);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$transaction = $withdrawal->transactions()->first();
|
$transaction = $withdrawal->transactions()->first();
|
||||||
$repository->shouldReceive('setUser');
|
$repository->shouldReceive('setUser');
|
||||||
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
|
$repository->shouldReceive('update')->andReturn($withdrawal)->once();
|
||||||
|
@ -27,6 +27,7 @@ namespace Tests\Unit\Services\Internal\Update;
|
|||||||
use FireflyIII\Factory\BudgetFactory;
|
use FireflyIII\Factory\BudgetFactory;
|
||||||
use FireflyIII\Factory\CategoryFactory;
|
use FireflyIII\Factory\CategoryFactory;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
|
use FireflyIII\Services\Internal\Update\TransactionUpdateService;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@ -119,8 +120,7 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
|
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
|
||||||
|
$data = [
|
||||||
$data = [
|
|
||||||
'currency_id' => 1,
|
'currency_id' => 1,
|
||||||
'currency_code' => null,
|
'currency_code' => null,
|
||||||
'description' => 'Some new description',
|
'description' => 'Some new description',
|
||||||
@ -137,6 +137,11 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
'foreign_currency_code' => null,
|
'foreign_currency_code' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// mock repository:
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('setUser');
|
||||||
|
$accountRepos->shouldReceive('findNull')->andReturn($source->account);
|
||||||
|
|
||||||
/** @var TransactionUpdateService $service */
|
/** @var TransactionUpdateService $service */
|
||||||
$service = app(TransactionUpdateService::class);
|
$service = app(TransactionUpdateService::class);
|
||||||
$service->setUser($this->user());
|
$service->setUser($this->user());
|
||||||
@ -154,7 +159,6 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
|
$source = $this->user()->transactions()->where('amount', '>', 0)->inRandomOrder()->first();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'currency_id' => 1,
|
'currency_id' => 1,
|
||||||
'currency_code' => null,
|
'currency_code' => null,
|
||||||
@ -172,11 +176,18 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
'foreign_currency_code' => null,
|
'foreign_currency_code' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// mock repository:
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('setUser');
|
||||||
|
$accountRepos->shouldReceive('findNull')->andReturn($source->account);
|
||||||
|
|
||||||
/** @var TransactionUpdateService $service */
|
/** @var TransactionUpdateService $service */
|
||||||
$service = app(TransactionUpdateService::class);
|
$service = app(TransactionUpdateService::class);
|
||||||
$service->setUser($this->user());
|
$service->setUser($this->user());
|
||||||
$result = $service->update($source, $data);
|
$result = $service->update($source, $data);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals($source->id, $result->id);
|
$this->assertEquals($source->id, $result->id);
|
||||||
$this->assertEquals($result->description, $data['description']);
|
$this->assertEquals($result->description, $data['description']);
|
||||||
$this->assertEquals($data['foreign_amount'], $result->foreign_amount);
|
$this->assertEquals($data['foreign_amount'], $result->foreign_amount);
|
||||||
@ -191,7 +202,6 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
/** @var Transaction $source */
|
/** @var Transaction $source */
|
||||||
$source = $this->user()->transactions()->where('amount', '<', 0)->inRandomOrder()->first();
|
$source = $this->user()->transactions()->where('amount', '<', 0)->inRandomOrder()->first();
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'currency_id' => 1,
|
'currency_id' => 1,
|
||||||
'currency_code' => null,
|
'currency_code' => null,
|
||||||
@ -209,6 +219,11 @@ class TransactionUpdateServiceTest extends TestCase
|
|||||||
'foreign_currency_code' => null,
|
'foreign_currency_code' => null,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// mock repository:
|
||||||
|
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepos->shouldReceive('setUser');
|
||||||
|
$accountRepos->shouldReceive('findNull')->andReturn($source->account);
|
||||||
|
|
||||||
/** @var TransactionUpdateService $service */
|
/** @var TransactionUpdateService $service */
|
||||||
$service = app(TransactionUpdateService::class);
|
$service = app(TransactionUpdateService::class);
|
||||||
$service->setUser($this->user());
|
$service->setUser($this->user());
|
||||||
|
Loading…
Reference in New Issue
Block a user