firefly-iii/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php

86 lines
2.9 KiB
PHP
Raw Normal View History

2019-06-09 08:28:54 -05:00
<?php
/**
* CategoryControllerTest.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/>.
*/
2019-08-17 05:09:03 -05:00
declare(strict_types=1);
2019-06-09 08:28:54 -05:00
namespace Tests\Api\V1\Controllers\Chart;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
2019-08-29 10:53:25 -05:00
use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface;
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
2019-06-09 08:28:54 -05:00
use Laravel\Passport\Passport;
use Log;
2019-08-29 10:53:25 -05:00
use Tests\Support\TestDataTrait;
2019-06-09 08:28:54 -05:00
use Tests\TestCase;
/**
* Class CategoryControllerTest
2019-08-17 03:48:28 -05:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2019-06-09 08:28:54 -05:00
*/
class CategoryControllerTest extends TestCase
{
2019-08-29 10:53:25 -05:00
use TestDataTrait;
2019-06-09 08:28:54 -05:00
/**
*
*/
public function setUp(): void
{
parent::setUp();
Passport::actingAs($this->user());
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Api\V1\Controllers\Chart\CategoryController
*/
public function testOverview(): void
{
$repository = $this->mock(CategoryRepositoryInterface::class);
2019-08-29 10:53:25 -05:00
$noCatRepos =$this->mock(NoCategoryRepositoryInterface::class);
$opsRepos = $this->mock(OperationsRepositoryInterface::class);
2019-06-09 08:28:54 -05:00
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
2019-08-29 10:53:25 -05:00
$noCatRepos->shouldReceive('setUser')->atLeast()->once();
$opsRepos->shouldReceive('setUser')->atLeast()->once();
$opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses());
$opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome());
$noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses());
$noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome());
2019-06-09 08:28:54 -05:00
$parameters = [
'start' => '2019-01-01',
'end' => '2019-01-31',
];
$response = $this->get(route('api.v1.chart.category.overview') . '?' . http_build_query($parameters), ['Accept' => 'application/json']);
$response->assertStatus(200);
}
2019-08-17 05:09:03 -05:00
}