2018-03-01 20:54:50 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PiggyBankEventFactoryTest.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\Factory;
|
|
|
|
|
|
|
|
|
|
|
|
use FireflyIII\Factory\PiggyBankEventFactory;
|
|
|
|
use FireflyIII\Models\PiggyBankEvent;
|
|
|
|
use FireflyIII\Models\PiggyBankRepetition;
|
|
|
|
use FireflyIII\Models\TransactionJournal;
|
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
2018-08-24 07:18:33 +02:00
|
|
|
use Log;
|
2018-03-01 20:54:50 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class PiggyBankEventFactoryTest
|
|
|
|
*/
|
|
|
|
class PiggyBankEventFactoryTest extends TestCase
|
|
|
|
{
|
2018-08-24 07:18:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-08-24 07:18:33 +02:00
|
|
|
}
|
|
|
|
|
2018-03-01 20:54:50 +01:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Factory\PiggyBankEventFactory
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreateAmountZero(): void
|
2018-03-01 20:54:50 +01:00
|
|
|
{
|
2019-04-10 19:03:33 +02:00
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
|
|
|
|
|
|
|
return;
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var TransactionJournal $transfer */
|
|
|
|
$transfer = $this->user()->transactionJournals()->where('transaction_type_id', 3)->first();
|
|
|
|
$piggy = $this->user()->piggyBanks()->first();
|
|
|
|
$repetition = PiggyBankRepetition::first();
|
|
|
|
$repos = $this->mock(PiggyBankRepositoryInterface::class);
|
|
|
|
/** @var PiggyBankEventFactory $factory */
|
|
|
|
$factory = app(PiggyBankEventFactory::class);
|
|
|
|
|
|
|
|
// mock:
|
|
|
|
$repos->shouldReceive('setUser');
|
|
|
|
$repos->shouldReceive('getRepetition')->andReturn($repetition);
|
|
|
|
$repos->shouldReceive('getExactAmount')->andReturn('0');
|
|
|
|
|
|
|
|
$this->assertNull($factory->create($transfer, $piggy));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Factory\PiggyBankEventFactory
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreateNoPiggy(): void
|
2019-06-13 18:07:49 +02:00
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
2019-04-10 19:03:33 +02:00
|
|
|
|
|
|
|
return;
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var TransactionJournal $transfer */
|
|
|
|
$transfer = $this->user()->transactionJournals()->where('transaction_type_id', 3)->first();
|
|
|
|
|
|
|
|
/** @var PiggyBankEventFactory $factory */
|
|
|
|
$factory = app(PiggyBankEventFactory::class);
|
|
|
|
|
|
|
|
$this->assertNull($factory->create($transfer, null));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-04-28 05:40:23 +02:00
|
|
|
* Test for withdrawal where piggy has no repetition.
|
|
|
|
*
|
2018-03-01 20:54:50 +01:00
|
|
|
* @covers \FireflyIII\Factory\PiggyBankEventFactory
|
|
|
|
*/
|
2018-04-28 05:40:23 +02:00
|
|
|
public function testCreateNoRep(): void
|
2019-06-13 18:07:49 +02:00
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
2019-04-10 19:03:33 +02:00
|
|
|
|
|
|
|
return;
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var TransactionJournal $transfer */
|
2018-04-28 05:40:23 +02:00
|
|
|
$transfer = $this->user()->transactionJournals()->where('transaction_type_id', 3)->first();
|
|
|
|
$piggy = $this->user()->piggyBanks()->first();
|
|
|
|
$repos = $this->mock(PiggyBankRepositoryInterface::class);
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var PiggyBankEventFactory $factory */
|
|
|
|
$factory = app(PiggyBankEventFactory::class);
|
|
|
|
|
|
|
|
// mock:
|
|
|
|
$repos->shouldReceive('setUser');
|
2018-04-28 05:40:23 +02:00
|
|
|
$repos->shouldReceive('getRepetition')->andReturn(null);
|
2018-03-01 20:54:50 +01:00
|
|
|
$repos->shouldReceive('getExactAmount')->andReturn('0');
|
|
|
|
|
|
|
|
$this->assertNull($factory->create($transfer, $piggy));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Factory\PiggyBankEventFactory
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreateNotTransfer(): void
|
2019-06-13 18:07:49 +02:00
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
2019-04-10 19:03:33 +02:00
|
|
|
|
|
|
|
return;
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var TransactionJournal $deposit */
|
|
|
|
$deposit = $this->user()->transactionJournals()->where('transaction_type_id', 2)->first();
|
|
|
|
$piggy = $this->user()->piggyBanks()->first();
|
|
|
|
/** @var PiggyBankEventFactory $factory */
|
|
|
|
$factory = app(PiggyBankEventFactory::class);
|
|
|
|
|
|
|
|
$this->assertNull($factory->create($deposit, $piggy));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Factory\PiggyBankEventFactory
|
|
|
|
*/
|
2018-05-11 19:58:10 +02:00
|
|
|
public function testCreateSuccess(): void
|
2019-06-13 18:07:49 +02:00
|
|
|
{
|
|
|
|
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
2019-04-10 19:03:33 +02:00
|
|
|
|
|
|
|
return;
|
2018-03-01 20:54:50 +01:00
|
|
|
/** @var TransactionJournal $transfer */
|
|
|
|
$transfer = $this->user()->transactionJournals()->where('transaction_type_id', 3)->first();
|
|
|
|
$piggy = $this->user()->piggyBanks()->first();
|
|
|
|
$repetition = PiggyBankRepetition::first();
|
|
|
|
$event = PiggyBankEvent::first();
|
|
|
|
$repos = $this->mock(PiggyBankRepositoryInterface::class);
|
|
|
|
/** @var PiggyBankEventFactory $factory */
|
|
|
|
$factory = app(PiggyBankEventFactory::class);
|
|
|
|
|
|
|
|
// mock:
|
|
|
|
$repos->shouldReceive('setUser');
|
|
|
|
$repos->shouldReceive('getRepetition')->andReturn($repetition);
|
|
|
|
$repos->shouldReceive('getExactAmount')->andReturn('5');
|
|
|
|
$repos->shouldReceive('addAmountToRepetition')->once();
|
|
|
|
$repos->shouldReceive('createEventWithJournal')->once()->andReturn($event);
|
|
|
|
|
|
|
|
$result = $factory->create($transfer, $piggy);
|
|
|
|
$this->assertEquals($result->id, $event->id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-03-04 15:14:29 +01:00
|
|
|
}
|